Skip to content

Commit 5207b32

Browse files
Ensure NmtBase.state always returns a string (#506)
Fixes #500
1 parent fa74236 commit 5207b32

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

canopen/nmt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ def state(self) -> str:
8686
- 'RESET'
8787
- 'RESET COMMUNICATION'
8888
"""
89-
if self._state in NMT_STATES:
89+
try:
9090
return NMT_STATES[self._state]
91-
else:
92-
return self._state
91+
except KeyError:
92+
return f"UNKNOWN STATE '{self._state}'"
9393

9494
@state.setter
9595
def state(self, new_state: str):

test/test_nmt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,11 @@ def test_nmt_master_on_heartbeat_initialising(self):
8888
state = self.node.nmt.wait_for_heartbeat(self.TIMEOUT)
8989
self.assertEqual(state, "PRE-OPERATIONAL")
9090

91-
@unittest.expectedFailure
9291
def test_nmt_master_on_heartbeat_unknown_state(self):
9392
task = self.net.send_periodic(self.COB_ID, [0xcb], self.PERIOD)
9493
self.addCleanup(task.stop)
9594
state = self.node.nmt.wait_for_heartbeat(self.TIMEOUT)
96-
# Expect the high bit to be masked out, and and unknown state string to
95+
# Expect the high bit to be masked out, and a formatted string to
9796
# be returned.
9897
self.assertEqual(state, "UNKNOWN STATE '75'")
9998

0 commit comments

Comments
 (0)