28
28
CONF_TYPE ,
29
29
EVENT_HOMEASSISTANT_STOP ,
30
30
)
31
- from homeassistant .core import Event , HomeAssistant , ServiceCall , callback
31
+ from homeassistant .core import Event , HomeAssistant , ServiceCall
32
32
from homeassistant .helpers import config_validation as cv
33
33
from homeassistant .helpers .discovery import async_load_platform
34
34
from homeassistant .helpers .dispatcher import async_dispatcher_send
35
- from homeassistant .helpers .event import async_call_later
36
35
from homeassistant .helpers .typing import ConfigType
37
36
from homeassistant .util .hass_dict import HassKey
38
37
@@ -317,12 +316,16 @@ async def async_pb_connect(self) -> None:
317
316
try :
318
317
await self ._client .connect () # type: ignore[union-attr]
319
318
except ModbusException as exception_error :
320
- err = f"{ self .name } connect failed, retry in pymodbus ({ exception_error !s} )"
321
- self ._log_error (err )
319
+ self ._log_error (
320
+ f"{ self .name } connect failed, please check your configuration ({ exception_error !s} )"
321
+ )
322
322
return
323
323
message = f"modbus { self .name } communication open"
324
324
_LOGGER .info (message )
325
325
326
+ if self ._config_delay :
327
+ await asyncio .sleep (self ._config_delay )
328
+
326
329
async def async_setup (self ) -> bool :
327
330
"""Set up pymodbus client."""
328
331
try :
@@ -340,20 +343,8 @@ async def async_setup(self) -> bool:
340
343
self ._connect_task = self .hass .async_create_background_task (
341
344
self .async_pb_connect (), "modbus-connect"
342
345
)
343
-
344
- # Start counting down to allow modbus requests.
345
- if self ._config_delay :
346
- self ._async_cancel_listener = async_call_later (
347
- self .hass , self ._config_delay , self .async_end_delay
348
- )
349
346
return True
350
347
351
- @callback
352
- def async_end_delay (self , args : Any ) -> None :
353
- """End startup delay."""
354
- self ._async_cancel_listener = None
355
- self ._config_delay = 0
356
-
357
348
async def async_restart (self ) -> None :
358
349
"""Reconnect client."""
359
350
if self ._client :
@@ -425,8 +416,6 @@ async def async_pb_call(
425
416
use_call : str ,
426
417
) -> ModbusPDU | None :
427
418
"""Convert async to sync pymodbus call."""
428
- if self ._config_delay :
429
- return None
430
419
async with self ._lock :
431
420
if not self ._client :
432
421
return None
0 commit comments