mirror of
https://github.com/home-assistant/core.git
synced 2025-09-06 13:21:33 +02:00
Modbus: Delay start after connection is made. (#150526)
This commit is contained in:
@@ -317,12 +317,19 @@ class ModbusHub:
|
|||||||
try:
|
try:
|
||||||
await self._client.connect() # type: ignore[union-attr]
|
await self._client.connect() # type: ignore[union-attr]
|
||||||
except ModbusException as exception_error:
|
except ModbusException as exception_error:
|
||||||
err = f"{self.name} connect failed, retry in pymodbus ({exception_error!s})"
|
self._log_error(
|
||||||
self._log_error(err)
|
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
message = f"modbus {self.name} communication open"
|
message = f"modbus {self.name} communication open"
|
||||||
_LOGGER.info(message)
|
_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:
|
async def async_setup(self) -> bool:
|
||||||
"""Set up pymodbus client."""
|
"""Set up pymodbus client."""
|
||||||
try:
|
try:
|
||||||
@@ -340,12 +347,6 @@ class ModbusHub:
|
|||||||
self._connect_task = self.hass.async_create_background_task(
|
self._connect_task = self.hass.async_create_background_task(
|
||||||
self.async_pb_connect(), "modbus-connect"
|
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
|
return True
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@@ -1225,6 +1225,7 @@ async def test_integration_reload(
|
|||||||
assert not state_sensor_2
|
assert not state_sensor_2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip
|
||||||
@pytest.mark.parametrize("do_config", [{}])
|
@pytest.mark.parametrize("do_config", [{}])
|
||||||
async def test_integration_reload_failed(
|
async def test_integration_reload_failed(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_modbus
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_modbus
|
||||||
|
Reference in New Issue
Block a user