Skip to content

Commit 2093063

Browse files
committed
Branch P6.
1 parent 6a25b55 commit 2093063

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

custom_components/modbus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"iot_class": "local_polling",
77
"loggers": ["pymodbus"],
88
"requirements": ["pymodbus==3.9.2"],
9-
"version": "1.5.0"
9+
"version": "1.6.0"
1010
}

custom_components/modbus/modbus.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
DATA_MODBUS_HUBS: HassKey[dict[str, ModbusHub]] = HassKey(DOMAIN)
7373

74+
PRIMARY_RECONNECT_DELAY = 60
7475

7576
ConfEntry = namedtuple("ConfEntry", "call_type attr func_name value_attr_name") # noqa: PYI024
7677
RunEntry = namedtuple("RunEntry", "attr func value_attr_name") # noqa: PYI024
@@ -311,18 +312,21 @@ def _log_error(self, text: str) -> None:
311312

312313
async def async_pb_connect(self) -> None:
313314
"""Connect to device, async."""
314-
async with self._lock:
315-
try:
316-
await self._client.connect() # type: ignore[union-attr]
317-
except ModbusException as exception_error:
318-
self._log_error(
319-
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
320-
)
321-
return
322-
message = f"modbus {self.name} communication open"
323-
_LOGGER.info(message)
315+
while True:
316+
async with self._lock:
317+
try:
318+
if await self._client.connect(): # type: ignore[union-attr]
319+
_LOGGER.info(f"modbus {self.name} communication open")
320+
break
321+
except ModbusException as exception_error:
322+
self._log_error(
323+
f"{self.name} connect failed, please check your configuration ({exception_error!s})"
324+
)
325+
_LOGGER.info(
326+
f"modbus {self.name} connect NOT a success ! retrying in {PRIMARY_RECONNECT_DELAY} seconds"
327+
)
328+
await asyncio.sleep(PRIMARY_RECONNECT_DELAY)
324329

325-
# Start counting down to allow modbus requests.
326330
if self.config_delay:
327331
await asyncio.sleep(self.config_delay)
328332
self.config_delay = 0

0 commit comments

Comments
 (0)