From 74a454e9c0d4662786a33391a1e2dbff8f1d9ce4 Mon Sep 17 00:00:00 2001 From: sfstar Date: Wed, 29 Jan 2025 16:40:41 +0000 Subject: [PATCH] backport 2025.2 from remcom fork --- custom_components/victron/coordinator.py | 8 +++++++- custom_components/victron/hub.py | 12 ++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/custom_components/victron/coordinator.py b/custom_components/victron/coordinator.py index 452700b..e1d8019 100644 --- a/custom_components/victron/coordinator.py +++ b/custom_components/victron/coordinator.py @@ -6,7 +6,13 @@ from pymodbus.constants import Endian from pymodbus.payload import BinaryPayloadDecoder -from pymodbus.pdu.register_read_message import ReadHoldingRegistersResponse + +import pymodbus + +if "3.7.0" <= pymodbus.__version__ <= "3.7.4": + from pymodbus.pdu.register_read_message import ReadHoldingRegistersResponse +else: + from pymodbus.pdu.register_message import ReadHoldingRegistersResponse from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError diff --git a/custom_components/victron/hub.py b/custom_components/victron/hub.py index 655a7dc..eeed9e4 100644 --- a/custom_components/victron/hub.py +++ b/custom_components/victron/hub.py @@ -31,15 +31,15 @@ def disconnect(self): return None def write_register(self, unit, address, value): - with self._lock: - kwargs = {"slave": int(unit)} if unit else {} - return self._client.write_register(address, value, **kwargs) + slave = int(unit) if unit else 1 + return self._client.write_register(address=address, value=value, slave=slave) def read_holding_registers(self, unit, address, count): """Read holding registers.""" - with self._lock: - kwargs = {"slave": int(unit)} if unit else {} - return self._client.read_holding_registers(address, count, **kwargs) + slave = int(unit) if unit else 1 + return self._client.read_holding_registers( + address=address, count=count, slave=slave + ) def calculate_register_count(self, registerInfoDict: OrderedDict): first_key = next(iter(registerInfoDict))