Fix tplink child updates taking up to 60s (#137782)
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Fix tplink child updates taking up to 60s
fixes #137562
* Revert "Fix tplink child updates taking up to 60s"
This reverts commit 5cd20a120f
.
pull/137088/head^2
parent
a542a2e021
commit
eab510f440
|
@ -46,9 +46,11 @@ class TPLinkDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||
device: Device,
|
||||
update_interval: timedelta,
|
||||
config_entry: TPLinkConfigEntry,
|
||||
parent_coordinator: TPLinkDataUpdateCoordinator | None = None,
|
||||
) -> None:
|
||||
"""Initialize DataUpdateCoordinator to gather data for specific SmartPlug."""
|
||||
self.device = device
|
||||
self.parent_coordinator = parent_coordinator
|
||||
|
||||
# The iot HS300 allows a limited number of concurrent requests and
|
||||
# fetching the emeter information requires separate ones, so child
|
||||
|
@ -95,6 +97,12 @@ class TPLinkDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||
) from ex
|
||||
|
||||
await self._process_child_devices()
|
||||
if not self._update_children:
|
||||
# If the children are not being updated, it means this is an
|
||||
# IotStrip, and we need to tell the children to write state
|
||||
# since the power state is provided by the parent.
|
||||
for child_coordinator in self._child_coordinators.values():
|
||||
child_coordinator.async_set_updated_data(None)
|
||||
|
||||
async def _process_child_devices(self) -> None:
|
||||
"""Process child devices and remove stale devices."""
|
||||
|
@ -132,7 +140,11 @@ class TPLinkDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||
# The child coordinators only update energy data so we can
|
||||
# set a longer update interval to avoid flooding the device
|
||||
child_coordinator = TPLinkDataUpdateCoordinator(
|
||||
self.hass, child, timedelta(seconds=60), self.config_entry
|
||||
self.hass,
|
||||
child,
|
||||
timedelta(seconds=60),
|
||||
self.config_entry,
|
||||
parent_coordinator=self,
|
||||
)
|
||||
self._child_coordinators[child.device_id] = child_coordinator
|
||||
return child_coordinator
|
||||
|
|
|
@ -151,7 +151,13 @@ def async_refresh_after[_T: CoordinatedTPLinkEntity, **_P](
|
|||
"exc": str(ex),
|
||||
},
|
||||
) from ex
|
||||
await self.coordinator.async_request_refresh()
|
||||
coordinator = self.coordinator
|
||||
if coordinator.parent_coordinator:
|
||||
# If there is a parent coordinator we need to refresh
|
||||
# the parent as its what provides the power state data
|
||||
# for the child entities.
|
||||
coordinator = coordinator.parent_coordinator
|
||||
await coordinator.async_request_refresh()
|
||||
|
||||
return _async_wrap
|
||||
|
||||
|
|
Loading…
Reference in New Issue