mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Rework how shade updates are processed in powerview (#110928)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
98a8714705
commit
83859bd342
@ -57,13 +57,24 @@ async def async_setup_entry(
|
|||||||
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
||||||
coordinator: PowerviewShadeUpdateCoordinator = pv_entry.coordinator
|
coordinator: PowerviewShadeUpdateCoordinator = pv_entry.coordinator
|
||||||
|
|
||||||
|
async def _async_initial_refresh() -> None:
|
||||||
|
"""Force position refresh shortly after adding.
|
||||||
|
|
||||||
|
Legacy shades can become out of sync with hub when moved
|
||||||
|
using physical remotes. This also allows reducing speed
|
||||||
|
of calls to older generation hubs in an effort to
|
||||||
|
prevent hub crashes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
for shade in pv_entry.shade_data.values():
|
||||||
|
with suppress(TimeoutError):
|
||||||
|
# hold off to avoid spamming the hub
|
||||||
|
async with asyncio.timeout(10):
|
||||||
|
_LOGGER.debug("Initial refresh of shade: %s", shade.name)
|
||||||
|
await shade.refresh()
|
||||||
|
|
||||||
entities: list[ShadeEntity] = []
|
entities: list[ShadeEntity] = []
|
||||||
for shade in pv_entry.shade_data.values():
|
for shade in pv_entry.shade_data.values():
|
||||||
# The shade may be out of sync with the hub
|
|
||||||
# so we force a refresh when we add it if possible
|
|
||||||
with suppress(TimeoutError):
|
|
||||||
async with asyncio.timeout(1):
|
|
||||||
await shade.refresh()
|
|
||||||
coordinator.data.update_shade_position(shade.id, shade.current_position)
|
coordinator.data.update_shade_position(shade.id, shade.current_position)
|
||||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||||
entities.extend(
|
entities.extend(
|
||||||
@ -74,6 +85,13 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
# background the fetching of state for initial launch
|
||||||
|
entry.async_create_background_task(
|
||||||
|
hass,
|
||||||
|
_async_initial_refresh(),
|
||||||
|
f"powerview {entry.title} initial shade refresh",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PowerViewShadeBase(ShadeEntity, CoverEntity):
|
class PowerViewShadeBase(ShadeEntity, CoverEntity):
|
||||||
"""Representation of a powerview shade."""
|
"""Representation of a powerview shade."""
|
||||||
@ -305,8 +323,8 @@ class PowerViewShadeBase(ShadeEntity, CoverEntity):
|
|||||||
# error if are already have one in flight
|
# error if are already have one in flight
|
||||||
return
|
return
|
||||||
# suppress timeouts caused by hub nightly reboot
|
# suppress timeouts caused by hub nightly reboot
|
||||||
with suppress(asyncio.TimeoutError):
|
with suppress(TimeoutError):
|
||||||
async with asyncio.timeout(5):
|
async with asyncio.timeout(10):
|
||||||
await self._shade.refresh()
|
await self._shade.refresh()
|
||||||
_LOGGER.debug("Process update %s: %s", self.name, self._shade.current_position)
|
_LOGGER.debug("Process update %s: %s", self.name, self._shade.current_position)
|
||||||
self._async_update_shade_data(self._shade.current_position)
|
self._async_update_shade_data(self._shade.current_position)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user