Skip to content

Commit 6b0c7cf

Browse files
authored
Fix "hearbeat" typos (fixes #389) (#453)
Rename the misspelled NmtMaster.add_hearbeat_callback() function to add_heartbeat_callback, with an assignment for the legacy name to not break compatibility in an unexpected manner. Adjust parameter / function documentation and local variables with the same typo consistently.
1 parent 4d10c84 commit 6b0c7cf

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

canopen/nmt.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,17 @@ def wait_for_bootup(self, timeout: float = 10) -> None:
163163
if self._state_received == 0:
164164
break
165165

166-
def add_hearbeat_callback(self, callback: Callable[[int], None]):
166+
def add_heartbeat_callback(self, callback: Callable[[int], None]):
167167
"""Add function to be called on heartbeat reception.
168168
169169
:param callback:
170170
Function that should accept an NMT state as only argument.
171171
"""
172172
self._callbacks.append(callback)
173173

174+
# Compatibility with previous typo
175+
add_hearbeat_callback = add_heartbeat_callback
176+
174177
def start_node_guarding(self, period: float):
175178
"""Starts the node guarding mechanism.
176179
@@ -225,29 +228,29 @@ def send_command(self, code: int) -> None:
225228

226229
def on_write(self, index, data, **kwargs):
227230
if index == 0x1017:
228-
hearbeat_time, = struct.unpack_from("<H", data)
229-
if hearbeat_time == 0:
231+
heartbeat_time, = struct.unpack_from("<H", data)
232+
if heartbeat_time == 0:
230233
self.stop_heartbeat()
231234
else:
232-
self.start_heartbeat(hearbeat_time)
235+
self.start_heartbeat(heartbeat_time)
233236

234237
def start_heartbeat(self, heartbeat_time_ms: int):
235-
"""Start the hearbeat service.
238+
"""Start the heartbeat service.
236239
237-
:param hearbeat_time
240+
:param heartbeat_time_ms
238241
The heartbeat time in ms. If the heartbeat time is 0
239242
the heartbeating will not start.
240243
"""
241244
self._heartbeat_time_ms = heartbeat_time_ms
242245

243246
self.stop_heartbeat()
244247
if heartbeat_time_ms > 0:
245-
logger.info("Start the hearbeat timer, interval is %d ms", self._heartbeat_time_ms)
248+
logger.info("Start the heartbeat timer, interval is %d ms", self._heartbeat_time_ms)
246249
self._send_task = self.network.send_periodic(
247250
0x700 + self.id, [self._state], heartbeat_time_ms / 1000.0)
248251

249252
def stop_heartbeat(self):
250-
"""Stop the hearbeat service."""
253+
"""Stop the heartbeat service."""
251254
if self._send_task is not None:
252255
logger.info("Stop the heartbeat timer")
253256
self._send_task.stop()

test/test_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_segmented_download(self):
8989
self.assertEqual(value, b"Another cool device")
9090

9191
def test_slave_send_heartbeat(self):
92-
# Setting the heartbeat time should trigger hearbeating
92+
# Setting the heartbeat time should trigger heartbeating
9393
# to start
9494
self.remote_node.sdo["Producer heartbeat time"].raw = 1000
9595
state = self.remote_node.nmt.wait_for_heartbeat()

0 commit comments

Comments
 (0)