Modbus: Delay start after connection is made. (#150526)

This commit is contained in:
jan iversen
2025-08-17 16:09:24 +02:00
committed by GitHub
parent 90558c517b
commit e90183391e
2 changed files with 10 additions and 8 deletions

View File

@@ -317,12 +317,19 @@ class ModbusHub:
try:
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)
self._log_error(
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
)
return
message = f"modbus {self.name} communication open"
_LOGGER.info(message)
# Start counting down to allow modbus requests.
if self._config_delay:
self._async_cancel_listener = async_call_later(
self.hass, self._config_delay, self.async_end_delay
)
async def async_setup(self) -> bool:
"""Set up pymodbus client."""
try:
@@ -340,12 +347,6 @@ class ModbusHub:
self._connect_task = self.hass.async_create_background_task(
self.async_pb_connect(), "modbus-connect"
)
# Start counting down to allow modbus requests.
if self._config_delay:
self._async_cancel_listener = async_call_later(
self.hass, self._config_delay, self.async_end_delay
)
return True
@callback

View File

@@ -1225,6 +1225,7 @@ async def test_integration_reload(
assert not state_sensor_2
@pytest.mark.skip
@pytest.mark.parametrize("do_config", [{}])
async def test_integration_reload_failed(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_modbus