From 96c716b1c525f01294897f674d73de0cc42d0cf0 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sat, 12 Apr 2025 11:10:35 +0200 Subject: [PATCH] missing explicit function return types added --- src/pyhoff/__init__.py | 6 +++--- src/pyhoff/devices.py | 4 ++-- src/pyhoff/modbus.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pyhoff/__init__.py b/src/pyhoff/__init__.py index 6f25896..4ddaf2c 100644 --- a/src/pyhoff/__init__.py +++ b/src/pyhoff/__init__.py @@ -41,7 +41,7 @@ class BusTerminal(): self._mixed_mapping = mixed_mapping @classmethod - def select(cls, bus_coupler: 'BusCoupler', terminal_number: int = 0): + def select(cls, bus_coupler: 'BusCoupler', terminal_number: int = 0) -> 'BusTerminal': terminal_list = [bt for bt in bus_coupler.bus_terminals if isinstance(bt, cls)] assert terminal_list, f'No instance of {cls.__name__} configured at this BusCoupler' assert 0 <= terminal_number < len(terminal_list), f'Out of range, select in range: 0..{len(terminal_list) - 1}' @@ -247,7 +247,7 @@ class BusCoupler(): self.add_bus_terminals(bus_terminals) self._init_hardware(watchdog) - def _init_hardware(self, watchdog: float): + def _init_hardware(self, watchdog: float) -> None: pass def add_bus_terminals(self, *new_bus_terminals: Type[BusTerminal] | Iterable[Type[BusTerminal]]) -> list[BusTerminal]: @@ -272,7 +272,7 @@ class BusCoupler(): for terminal_class in terminal_classes: assert _is_bus_terminal(terminal_class), f'{terminal_class} is not a bus terminal' - def get_para(key: str): + def get_para(key: str) -> int: return terminal_class.parameters.get(key, 0) new_terminal = terminal_class( diff --git a/src/pyhoff/devices.py b/src/pyhoff/devices.py index 70861e2..513b99c 100644 --- a/src/pyhoff/devices.py +++ b/src/pyhoff/devices.py @@ -7,7 +7,7 @@ class BK9000(BusCoupler): """ BK9000 ModBus TCP bus coupler """ - def _init_hardware(self, watchdog: float): + def _init_hardware(self, watchdog: float) -> None: # https://download.beckhoff.com/download/document/io/bus-terminals/bk9000_bk9050_bk9100de.pdf # config watchdog on page 58 @@ -44,7 +44,7 @@ class WAGO_750_352(BusCoupler): """ Wago 750-352 ModBus TCP bus coupler """ - def _init_hardware(self, watchdog: float): + def _init_hardware(self, watchdog: float) -> None: # deactivate/reset watchdog timer: self.modbus.write_single_register(0x1005, 0xAAAA) self.modbus.write_single_register(0x1005, 0x5555) diff --git a/src/pyhoff/modbus.py b/src/pyhoff/modbus.py index 80b2e90..7c4d11d 100644 --- a/src/pyhoff/modbus.py +++ b/src/pyhoff/modbus.py @@ -87,7 +87,7 @@ class SimpleModbusClient: self._socket: None | socket.socket = None self.debug = debug - def connect(self): + def connect(self) -> bool: for af, st, pr, _, sa in socket.getaddrinfo(self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM): @@ -110,7 +110,7 @@ class SimpleModbusClient: self.last_error = 'connection failed' return False - def close(self): + def close(self) -> bytes: """ Close connection