|
3 | 3 | import logging |
4 | 4 | import threading |
5 | 5 | from collections.abc import MutableMapping |
6 | | -from typing import Callable, Dict, Final, Iterator, List, Optional, Union |
7 | | -from typing import Callable, Dict, Iterator, List, Optional, Union, TYPE_CHECKING, TextIO |
| 6 | +from typing import Callable, Dict, Final, Iterator, List, Optional, Union, TYPE_CHECKING, TextIO |
8 | 7 |
|
9 | 8 | import can |
10 | 9 | from can import Listener |
@@ -168,7 +167,7 @@ def add_node( |
168 | 167 |
|
169 | 168 | def create_node( |
170 | 169 | self, |
171 | | - node: int, |
| 170 | + node: Union[int, LocalNode], |
172 | 171 | object_dictionary: Union[str, ObjectDictionary, TextIO, None] = None, |
173 | 172 | ) -> LocalNode: |
174 | 173 | """Create a local node in the network. |
@@ -234,6 +233,8 @@ def send_periodic( |
234 | 233 | :return: |
235 | 234 | An task object with a ``.stop()`` method to stop the transmission |
236 | 235 | """ |
| 236 | + if not self.bus: |
| 237 | + raise RuntimeError("Not connected to CAN bus") |
237 | 238 | return PeriodicMessageTask(can_id, data, period, self.bus, remote) |
238 | 239 |
|
239 | 240 | def notify(self, can_id: int, data: bytearray, timestamp: float) -> None: |
@@ -315,7 +316,7 @@ def __init__( |
315 | 316 | can_id: int, |
316 | 317 | data: CanData, |
317 | 318 | period: float, |
318 | | - bus, |
| 319 | + bus: can.BusABC, |
319 | 320 | remote: bool = False, |
320 | 321 | ): |
321 | 322 | """ |
@@ -352,12 +353,10 @@ def update(self, data: bytes) -> None: |
352 | 353 | old_data = self.msg.data |
353 | 354 | self.msg.data = new_data |
354 | 355 | if hasattr(self._task, "modify_data"): |
355 | | - assert self._task is not None # This will never be None, but mypy needs this |
356 | 356 | self._task.modify_data(self.msg) |
357 | 357 | elif new_data != old_data: |
358 | 358 | # Stop and start (will mess up period unfortunately) |
359 | | - if self._task is not None: |
360 | | - self._task.stop() |
| 359 | + self._task.stop() |
361 | 360 | self._start() |
362 | 361 |
|
363 | 362 |
|
|
0 commit comments