Skip to content

Commit

Permalink
Ensure NmtBase.state return a string for unknown states
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Jul 9, 2024
1 parent fa74236 commit 991af60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 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
1 change: 0 additions & 1 deletion test/test_nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ 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)
Expand Down

0 comments on commit 991af60

Please sign in to comment.