Modbus: Do not remove non-duplicate error log. (#150511)

This commit is contained in:
jan iversen
2025-08-12 21:16:43 +02:00
committed by GitHub
parent 6fa7c6cb81
commit 452322e971

View File

@@ -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: