From 452322e97180294e7aebb12ac8ddf66fd43f464b Mon Sep 17 00:00:00 2001 From: jan iversen Date: Tue, 12 Aug 2025 21:16:43 +0200 Subject: [PATCH] Modbus: Do not remove non-duplicate error log. (#150511) --- homeassistant/components/modbus/modbus.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index 9e0ba63b4a0..1bd17f17b36 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -263,6 +263,7 @@ class ModbusHub: self._config_delay = client_config[CONF_DELAY] self._pb_request: dict[str, RunEntry] = {} self._connect_task: asyncio.Task + self._last_log_error: str = "" self._pb_class = { SERIAL: AsyncModbusSerialClient, TCP: AsyncModbusTcpClient, @@ -303,13 +304,12 @@ class ModbusHub: else: self._msg_wait = 0 - def _log_error(self, text: str, error_state: bool = True) -> None: + def _log_error(self, text: str) -> None: + if text == self._last_log_error: + return + self._last_log_error = text log_text = f"Pymodbus: {self.name}: {text}" - if self._in_error: - _LOGGER.debug(log_text) - else: - _LOGGER.error(log_text) - self._in_error = error_state + _LOGGER.error(log_text) async def async_pb_connect(self) -> None: """Connect to device, async.""" @@ -318,7 +318,7 @@ class ModbusHub: await self._client.connect() # type: ignore[union-attr] except ModbusException as exception_error: err = f"{self.name} connect failed, retry in pymodbus ({exception_error!s})" - self._log_error(err, error_state=False) + self._log_error(err) return message = f"modbus {self.name} communication open" _LOGGER.info(message) @@ -328,7 +328,7 @@ class ModbusHub: try: self._client = self._pb_class[self._config_type](**self._pb_params) except ModbusException as exception_error: - self._log_error(str(exception_error), error_state=False) + self._log_error(str(exception_error)) return False for entry in PB_CALL: