mirror of
https://github.com/home-assistant/core.git
synced 2025-09-06 05:11:35 +02:00
Modbus: Retry primary connect. (#150853)
This commit is contained in:
@@ -71,6 +71,7 @@ from .validators import check_config
|
|||||||
|
|
||||||
DATA_MODBUS_HUBS: HassKey[dict[str, ModbusHub]] = HassKey(DOMAIN)
|
DATA_MODBUS_HUBS: HassKey[dict[str, ModbusHub]] = HassKey(DOMAIN)
|
||||||
|
|
||||||
|
PRIMARY_RECONNECT_DELAY = 60
|
||||||
|
|
||||||
ConfEntry = namedtuple("ConfEntry", "call_type attr func_name value_attr_name") # noqa: PYI024
|
ConfEntry = namedtuple("ConfEntry", "call_type attr func_name value_attr_name") # noqa: PYI024
|
||||||
RunEntry = namedtuple("RunEntry", "attr func value_attr_name") # noqa: PYI024
|
RunEntry = namedtuple("RunEntry", "attr func value_attr_name") # noqa: PYI024
|
||||||
@@ -311,18 +312,21 @@ class ModbusHub:
|
|||||||
|
|
||||||
async def async_pb_connect(self) -> None:
|
async def async_pb_connect(self) -> None:
|
||||||
"""Connect to device, async."""
|
"""Connect to device, async."""
|
||||||
async with self._lock:
|
while True:
|
||||||
try:
|
async with self._lock:
|
||||||
await self._client.connect() # type: ignore[union-attr]
|
try:
|
||||||
except ModbusException as exception_error:
|
if await self._client.connect(): # type: ignore[union-attr]
|
||||||
self._log_error(
|
_LOGGER.info(f"modbus {self.name} communication open")
|
||||||
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
|
break
|
||||||
)
|
except ModbusException as exception_error:
|
||||||
return
|
self._log_error(
|
||||||
message = f"modbus {self.name} communication open"
|
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
|
||||||
_LOGGER.info(message)
|
)
|
||||||
|
_LOGGER.info(
|
||||||
|
f"modbus {self.name} connect NOT a success ! retrying in {PRIMARY_RECONNECT_DELAY} seconds"
|
||||||
|
)
|
||||||
|
await asyncio.sleep(PRIMARY_RECONNECT_DELAY)
|
||||||
|
|
||||||
# Start counting down to allow modbus requests.
|
|
||||||
if self.config_delay:
|
if self.config_delay:
|
||||||
await asyncio.sleep(self.config_delay)
|
await asyncio.sleep(self.config_delay)
|
||||||
self.config_delay = 0
|
self.config_delay = 0
|
||||||
|
Reference in New Issue
Block a user