From 6a440ca270ececc2789b0ca77c9c7e02159614a3 Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 13 Feb 2024 11:19:52 -0600 Subject: [PATCH 1/2] solve more mypy issues with datastore --- pymodbus/datastore/simulator.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index 76230f62c..babcaf73d 100644 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -37,6 +37,18 @@ class Cell: count_write: int = 0 +class TextCell: + """A textual representation of a single cell.""" + + type: str + access: str + value: str + action: str + action_kwargs: str + count_read: str + count_write: str + + @dataclasses.dataclass class Label: # pylint: disable=too-many-instance-attributes """Defines all dict values. @@ -94,7 +106,7 @@ class Setup: def __init__(self, runtime): """Initialize.""" self.runtime = runtime - self.config = None + self.config = {} self.config_types = { Label.type_bits: { Label.type: CellType.BITS, @@ -454,10 +466,10 @@ class ModbusSimulatorContext: start_time = int(datetime.now().timestamp()) def __init__( - self, config: dict[str, Any], custom_actions: dict[str, Callable] + self, config: dict[str, Any], custom_actions: dict[str, Callable] | None ) -> None: """Initialize.""" - self.registers: list[int] = [] + self.registers: list[Cell] = [] self.fc_offset: dict[int, int] = {} self.register_count = 0 self.type_exception = False @@ -474,7 +486,7 @@ def __init__( def get_text_register(self, register): """Get raw register.""" reg = self.registers[register] - text_cell = Cell() + text_cell = TextCell() # pylint: disable=no-value-for-parameter text_cell.type = self.registerType_id_to_name[reg.type] text_cell.access = str(reg.access) text_cell.count_read = str(reg.count_read) From a2a8f79c623019b61a6b074f439dd094064b2fad Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Tue, 13 Feb 2024 15:33:34 -0600 Subject: [PATCH 2/2] pylint make up your mind! --- pymodbus/datastore/simulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index babcaf73d..d94d3c1ae 100644 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -37,7 +37,7 @@ class Cell: count_write: int = 0 -class TextCell: +class TextCell: # pylint: disable=too-few-public-methods """A textual representation of a single cell.""" type: str @@ -486,7 +486,7 @@ def __init__( def get_text_register(self, register): """Get raw register.""" reg = self.registers[register] - text_cell = TextCell() # pylint: disable=no-value-for-parameter + text_cell = TextCell() text_cell.type = self.registerType_id_to_name[reg.type] text_cell.access = str(reg.access) text_cell.count_read = str(reg.count_read)