Skip to content

Commit

Permalink
Ensure NmtBase.state always returns a string (#506)
Browse files Browse the repository at this point in the history
Fixes #500
  • Loading branch information
erlend-aasland authored Jul 9, 2024
1 parent fa74236 commit 5207b32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions canopen/nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def state(self) -> str:
- 'RESET'
- 'RESET COMMUNICATION'
"""
if self._state in NMT_STATES:
try:
return NMT_STATES[self._state]
else:
return self._state
except KeyError:
return f"UNKNOWN STATE '{self._state}'"

@state.setter
def state(self, new_state: str):
Expand Down
3 changes: 1 addition & 2 deletions test/test_nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ def test_nmt_master_on_heartbeat_initialising(self):
state = self.node.nmt.wait_for_heartbeat(self.TIMEOUT)
self.assertEqual(state, "PRE-OPERATIONAL")

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

Expand Down

0 comments on commit 5207b32

Please sign in to comment.