Skip to content

Commit 09c1ddd

Browse files
Add some type annotations for the nmt module (#586)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent bc917f0 commit 09c1ddd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

canopen/nmt.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import struct
33
import threading
44
import time
5-
from typing import Callable, Optional, TYPE_CHECKING
5+
from typing import Callable, Dict, Final, List, Optional, TYPE_CHECKING
66

77
import canopen.network
88

@@ -12,7 +12,7 @@
1212

1313
logger = logging.getLogger(__name__)
1414

15-
NMT_STATES = {
15+
NMT_STATES: Final[Dict[int, str]] = {
1616
0: 'INITIALISING',
1717
4: 'STOPPED',
1818
5: 'OPERATIONAL',
@@ -21,7 +21,7 @@
2121
127: 'PRE-OPERATIONAL'
2222
}
2323

24-
NMT_COMMANDS = {
24+
NMT_COMMANDS: Final[Dict[str, int]] = {
2525
'OPERATIONAL': 1,
2626
'STOPPED': 2,
2727
'SLEEP': 80,
@@ -32,7 +32,7 @@
3232
'RESET COMMUNICATION': 130
3333
}
3434

35-
COMMAND_TO_STATE = {
35+
COMMAND_TO_STATE: Final[Dict[int, int]] = {
3636
1: 5,
3737
2: 4,
3838
80: 80,
@@ -117,7 +117,7 @@ def __init__(self, node_id: int):
117117
#: Timestamp of last heartbeat message
118118
self.timestamp: Optional[float] = None
119119
self.state_update = threading.Condition()
120-
self._callbacks = []
120+
self._callbacks: List[Callable[[int], None]] = []
121121

122122
def on_heartbeat(self, can_id, data, timestamp):
123123
with self.state_update:
@@ -186,7 +186,8 @@ def start_node_guarding(self, period: float):
186186
:param period:
187187
Period (in seconds) at which the node guarding should be advertised to the slave node.
188188
"""
189-
if self._node_guarding_producer : self.stop_node_guarding()
189+
if self._node_guarding_producer:
190+
self.stop_node_guarding()
190191
self._node_guarding_producer = self.network.send_periodic(0x700 + self.id, None, period, True)
191192

192193
def stop_node_guarding(self):

0 commit comments

Comments
 (0)