Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure NmtBase.state always returns a string #506

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading