Skip to content

Commit b57e24b

Browse files
committed
Start update AFTER connection.
1 parent 9ba84fb commit b57e24b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

custom_components/modbus/entity.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ async def _async_update_if_not_in_progress(
137137
@callback
138138
def async_run(self) -> None:
139139
"""Remote start entity."""
140+
_LOGGER.debug(f"Start updating {self._attr_name}")
140141
self._async_cancel_update_polling()
141142
self._async_schedule_future_update(0.1)
142143
if self._scan_interval > 0:
@@ -177,9 +178,15 @@ def async_hold(self) -> None:
177178
self._attr_available = False
178179
self.async_write_ha_state()
179180

181+
async def async_await_connection(self) -> None:
182+
"""Wait for first connect."""
183+
await self._hub.event_connected.wait()
184+
self.async_run()
185+
180186
async def async_base_added_to_hass(self) -> None:
181187
"""Handle entity which will be added."""
182-
self.async_run()
188+
no_use = asyncio.create_task(self.async_await_connection())
189+
_LOGGER.debug(f"connect task {no_use}")
183190
self.async_on_remove(
184191
async_dispatcher_connect(self.hass, SIGNAL_STOP_ENTITY, self.async_hold)
185192
)

custom_components/modbus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"issue_tracker": "https://github.com/pymodbus-dev/homeassistant_modbus/issues",
88
"loggers": ["pymodbus"],
99
"requirements": ["pymodbus==3.11.1"],
10-
"version": "1.0.3"
10+
"version": "1.0.4"
1111
}

custom_components/modbus/modbus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def __init__(self, hass: HomeAssistant, client_config: dict[str, Any]) -> None:
256256
self._async_cancel_listener: Callable[[], None] | None = None
257257
self._in_error = False
258258
self._lock = asyncio.Lock()
259+
self.event_connected = asyncio.Event()
259260
self.hass = hass
260261
self.name = client_config[CONF_NAME]
261262
self._config_type = client_config[CONF_TYPE]
@@ -325,6 +326,7 @@ async def async_pb_connect(self) -> None:
325326

326327
if self._config_delay:
327328
await asyncio.sleep(self._config_delay)
329+
self.event_connected.set()
328330

329331
async def async_setup(self) -> bool:
330332
"""Set up pymodbus client."""

0 commit comments

Comments
 (0)