Bump pymodbus version 3.7.4 (#133175)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
Claudio Ruggeri - CR-Tech 2024-12-15 12:24:27 +01:00 committed by GitHub
parent 85ef2c0fb1
commit 760c3ac98c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 17 deletions

View File

@ -121,7 +121,7 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
else: else:
self._attr_available = True self._attr_available = True
if self._input_type in (CALL_TYPE_COIL, CALL_TYPE_DISCRETE): if self._input_type in (CALL_TYPE_COIL, CALL_TYPE_DISCRETE):
self._result = result.bits self._result = [int(bit) for bit in result.bits]
else: else:
self._result = result.registers self._result = result.registers
self._attr_is_on = bool(self._result[0] & 1) self._attr_is_on = bool(self._result[0] & 1)

View File

@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/modbus", "documentation": "https://www.home-assistant.io/integrations/modbus",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["pymodbus"], "loggers": ["pymodbus"],
"requirements": ["pymodbus==3.6.9"] "requirements": ["pymodbus==3.7.4"]
} }

View File

@ -14,8 +14,8 @@ from pymodbus.client import (
AsyncModbusUdpClient, AsyncModbusUdpClient,
) )
from pymodbus.exceptions import ModbusException from pymodbus.exceptions import ModbusException
from pymodbus.pdu import ModbusResponse from pymodbus.framer import FramerType
from pymodbus.transaction import ModbusAsciiFramer, ModbusRtuFramer, ModbusSocketFramer from pymodbus.pdu import ModbusPDU
import voluptuous as vol import voluptuous as vol
from homeassistant.const import ( from homeassistant.const import (
@ -265,14 +265,13 @@ class ModbusHub:
"port": client_config[CONF_PORT], "port": client_config[CONF_PORT],
"timeout": client_config[CONF_TIMEOUT], "timeout": client_config[CONF_TIMEOUT],
"retries": 3, "retries": 3,
"retry_on_empty": True,
} }
if self._config_type == SERIAL: if self._config_type == SERIAL:
# serial configuration # serial configuration
if client_config[CONF_METHOD] == "ascii": if client_config[CONF_METHOD] == "ascii":
self._pb_params["framer"] = ModbusAsciiFramer self._pb_params["framer"] = FramerType.ASCII
else: else:
self._pb_params["framer"] = ModbusRtuFramer self._pb_params["framer"] = FramerType.RTU
self._pb_params.update( self._pb_params.update(
{ {
"baudrate": client_config[CONF_BAUDRATE], "baudrate": client_config[CONF_BAUDRATE],
@ -285,9 +284,9 @@ class ModbusHub:
# network configuration # network configuration
self._pb_params["host"] = client_config[CONF_HOST] self._pb_params["host"] = client_config[CONF_HOST]
if self._config_type == RTUOVERTCP: if self._config_type == RTUOVERTCP:
self._pb_params["framer"] = ModbusRtuFramer self._pb_params["framer"] = FramerType.RTU
else: else:
self._pb_params["framer"] = ModbusSocketFramer self._pb_params["framer"] = FramerType.SOCKET
if CONF_MSG_WAIT in client_config: if CONF_MSG_WAIT in client_config:
self._msg_wait = client_config[CONF_MSG_WAIT] / 1000 self._msg_wait = client_config[CONF_MSG_WAIT] / 1000
@ -370,12 +369,12 @@ class ModbusHub:
async def low_level_pb_call( async def low_level_pb_call(
self, slave: int | None, address: int, value: int | list[int], use_call: str self, slave: int | None, address: int, value: int | list[int], use_call: str
) -> ModbusResponse | None: ) -> ModbusPDU | None:
"""Call sync. pymodbus.""" """Call sync. pymodbus."""
kwargs = {"slave": slave} if slave else {} kwargs = {"slave": slave} if slave else {}
entry = self._pb_request[use_call] entry = self._pb_request[use_call]
try: try:
result: ModbusResponse = await entry.func(address, value, **kwargs) result: ModbusPDU = await entry.func(address, value, **kwargs)
except ModbusException as exception_error: except ModbusException as exception_error:
error = f"Error: device: {slave} address: {address} -> {exception_error!s}" error = f"Error: device: {slave} address: {address} -> {exception_error!s}"
self._log_error(error) self._log_error(error)
@ -403,7 +402,7 @@ class ModbusHub:
address: int, address: int,
value: int | list[int], value: int | list[int],
use_call: str, use_call: str,
) -> ModbusResponse | None: ) -> ModbusPDU | None:
"""Convert async to sync pymodbus call.""" """Convert async to sync pymodbus call."""
if self._config_delay: if self._config_delay:
return None return None

View File

@ -2091,7 +2091,7 @@ pymitv==1.4.3
pymochad==0.2.0 pymochad==0.2.0
# homeassistant.components.modbus # homeassistant.components.modbus
pymodbus==3.6.9 pymodbus==3.7.4
# homeassistant.components.monoprice # homeassistant.components.monoprice
pymonoprice==0.4 pymonoprice==0.4

View File

@ -1696,7 +1696,7 @@ pymicro-vad==1.0.1
pymochad==0.2.0 pymochad==0.2.0
# homeassistant.components.modbus # homeassistant.components.modbus
pymodbus==3.6.9 pymodbus==3.7.4
# homeassistant.components.monoprice # homeassistant.components.monoprice
pymonoprice==0.4 pymonoprice==0.4

View File

@ -19,7 +19,7 @@ from unittest import mock
from freezegun.api import FrozenDateTimeFactory from freezegun.api import FrozenDateTimeFactory
from pymodbus.exceptions import ModbusException from pymodbus.exceptions import ModbusException
from pymodbus.pdu import ExceptionResponse, IllegalFunctionRequest from pymodbus.pdu import ExceptionResponse
import pytest import pytest
import voluptuous as vol import voluptuous as vol
@ -820,7 +820,6 @@ SERVICE = "service"
[ [
{VALUE: ReadResult([0x0001]), DATA: ""}, {VALUE: ReadResult([0x0001]), DATA: ""},
{VALUE: ExceptionResponse(0x06), DATA: "Pymodbus:"}, {VALUE: ExceptionResponse(0x06), DATA: "Pymodbus:"},
{VALUE: IllegalFunctionRequest(0x06), DATA: "Pymodbus:"},
{VALUE: ModbusException("fail write_"), DATA: "Pymodbus:"}, {VALUE: ModbusException("fail write_"), DATA: "Pymodbus:"},
], ],
) )
@ -928,7 +927,6 @@ async def mock_modbus_read_pymodbus_fixture(
("do_return", "do_exception", "do_expect_state", "do_expect_value"), ("do_return", "do_exception", "do_expect_state", "do_expect_value"),
[ [
(ReadResult([1]), None, STATE_ON, "1"), (ReadResult([1]), None, STATE_ON, "1"),
(IllegalFunctionRequest(0x99), None, STATE_UNAVAILABLE, STATE_UNAVAILABLE),
(ExceptionResponse(0x99), None, STATE_UNAVAILABLE, STATE_UNAVAILABLE), (ExceptionResponse(0x99), None, STATE_UNAVAILABLE, STATE_UNAVAILABLE),
( (
ReadResult([1]), ReadResult([1]),