File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 6
6
"iot_class" : " local_polling" ,
7
7
"loggers" : [" pymodbus" ],
8
8
"requirements" : [" pymodbus==3.9.2" ],
9
- "version" : " 1.5 .0"
9
+ "version" : " 1.6 .0"
10
10
}
Original file line number Diff line number Diff line change 71
71
72
72
DATA_MODBUS_HUBS : HassKey [dict [str , ModbusHub ]] = HassKey (DOMAIN )
73
73
74
+ PRIMARY_RECONNECT_DELAY = 60
74
75
75
76
ConfEntry = namedtuple ("ConfEntry" , "call_type attr func_name value_attr_name" ) # noqa: PYI024
76
77
RunEntry = namedtuple ("RunEntry" , "attr func value_attr_name" ) # noqa: PYI024
@@ -311,18 +312,21 @@ def _log_error(self, text: str) -> None:
311
312
312
313
async def async_pb_connect (self ) -> None :
313
314
"""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 )
324
329
325
- # Start counting down to allow modbus requests.
326
330
if self .config_delay :
327
331
await asyncio .sleep (self .config_delay )
328
332
self .config_delay = 0
You can’t perform that action at this time.
0 commit comments