Move powerview timeout logic to the upstream api (#113984)

This commit is contained in:
kingy444 2024-03-23 10:38:33 +11:00 committed by GitHub
parent efc54971d3
commit 26b6bd83fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 61 additions and 49 deletions

View File

@ -1,6 +1,4 @@
"""The Hunter Douglas PowerView integration.""" """The Hunter Douglas PowerView integration."""
import asyncio
import logging import logging
from aiopvapi.helpers.aiorequest import AioRequest from aiopvapi.helpers.aiorequest import AioRequest
@ -52,8 +50,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hub_address, loop=hass.loop, websession=websession, api_version=api_version hub_address, loop=hass.loop, websession=websession, api_version=api_version
) )
# default 15 second timeout for each call in upstream
try: try:
async with asyncio.timeout(10):
hub = Hub(pv_request) hub = Hub(pv_request)
await hub.query_firmware() await hub.query_firmware()
device_info = await async_get_device_info(hub) device_info = await async_get_device_info(hub)
@ -75,13 +73,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return False return False
try: try:
async with asyncio.timeout(10):
rooms = Rooms(pv_request) rooms = Rooms(pv_request)
room_data: PowerviewData = await rooms.get_rooms() room_data: PowerviewData = await rooms.get_rooms()
async with asyncio.timeout(10):
scenes = Scenes(pv_request) scenes = Scenes(pv_request)
scene_data: PowerviewData = await scenes.get_scenes() scene_data: PowerviewData = await scenes.get_scenes()
async with asyncio.timeout(10):
shades = Shades(pv_request) shades = Shades(pv_request)
shade_data: PowerviewData = await shades.get_shades() shade_data: PowerviewData = await shades.get_shades()
except HUB_EXCEPTIONS as err: except HUB_EXCEPTIONS as err:

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio
import logging import logging
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
@ -38,7 +37,6 @@ async def validate_input(hass: HomeAssistant, hub_address: str) -> dict[str, str
pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession) pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession)
try: try:
async with asyncio.timeout(10):
hub = Hub(pv_request) hub = Hub(pv_request)
await hub.query_firmware() await hub.query_firmware()
device_info = await async_get_device_info(hub) device_info = await async_get_device_info(hub)

View File

@ -2,7 +2,6 @@
from __future__ import annotations from __future__ import annotations
import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
@ -36,7 +35,6 @@ class PowerviewShadeUpdateCoordinator(DataUpdateCoordinator[PowerviewShadeData])
async def _async_update_data(self) -> PowerviewShadeData: async def _async_update_data(self) -> PowerviewShadeData:
"""Fetch data from shade endpoint.""" """Fetch data from shade endpoint."""
async with asyncio.timeout(10):
try: try:
shade_entries = await self.shades.get_shades() shade_entries = await self.shades.get_shades()
except PvApiMaintenance as error: except PvApiMaintenance as error:

View File

@ -2,9 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio
from collections.abc import Callable, Iterable from collections.abc import Callable, Iterable
from contextlib import suppress
from dataclasses import replace from dataclasses import replace
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
@ -68,11 +66,8 @@ async def async_setup_entry(
""" """
for shade in pv_entry.shade_data.values(): 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) _LOGGER.debug("Initial refresh of shade: %s", shade.name)
await shade.refresh() await shade.refresh(suppress_timeout=True) # default 15 second timeout
entities: list[ShadeEntity] = [] entities: list[ShadeEntity] = []
for shade in pv_entry.shade_data.values(): for shade in pv_entry.shade_data.values():
@ -324,9 +319,7 @@ 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(TimeoutError): await self._shade.refresh(suppress_timeout=True) # default 15 second timeout
async with asyncio.timeout(10):
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)

View File

@ -18,6 +18,6 @@
}, },
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["aiopvapi"], "loggers": ["aiopvapi"],
"requirements": ["aiopvapi==3.0.2"], "requirements": ["aiopvapi==3.1.1"],
"zeroconf": ["_powerview._tcp.local.", "_powerview-g3._tcp.local."] "zeroconf": ["_powerview._tcp.local.", "_powerview-g3._tcp.local."]
} }

View File

@ -62,7 +62,7 @@ SENSORS: Final = [
native_unit_fn=lambda shade: PERCENTAGE, native_unit_fn=lambda shade: PERCENTAGE,
native_value_fn=lambda shade: shade.get_battery_strength(), native_value_fn=lambda shade: shade.get_battery_strength(),
create_entity_fn=lambda shade: shade.is_battery_powered(), create_entity_fn=lambda shade: shade.is_battery_powered(),
update_fn=lambda shade: shade.refresh_battery(), update_fn=lambda shade: shade.refresh_battery(suppress_timeout=True),
), ),
PowerviewSensorDescription( PowerviewSensorDescription(
key="signal", key="signal",
@ -72,7 +72,7 @@ SENSORS: Final = [
native_unit_fn=get_signal_native_unit, native_unit_fn=get_signal_native_unit,
native_value_fn=lambda shade: shade.get_signal_strength(), native_value_fn=lambda shade: shade.get_signal_strength(),
create_entity_fn=lambda shade: shade.has_signal_strength(), create_entity_fn=lambda shade: shade.has_signal_strength(),
update_fn=lambda shade: shade.refresh(), update_fn=lambda shade: shade.refresh(suppress_timeout=True),
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
] ]

View File

@ -333,7 +333,7 @@ aiopulse==0.4.4
aiopurpleair==2022.12.1 aiopurpleair==2022.12.1
# homeassistant.components.hunterdouglas_powerview # homeassistant.components.hunterdouglas_powerview
aiopvapi==3.0.2 aiopvapi==3.1.1
# homeassistant.components.pvpc_hourly_pricing # homeassistant.components.pvpc_hourly_pricing
aiopvpc==4.2.2 aiopvpc==4.2.2

View File

@ -306,7 +306,7 @@ aiopulse==0.4.4
aiopurpleair==2022.12.1 aiopurpleair==2022.12.1
# homeassistant.components.hunterdouglas_powerview # homeassistant.components.hunterdouglas_powerview
aiopvapi==3.0.2 aiopvapi==3.1.1
# homeassistant.components.pvpc_hourly_pricing # homeassistant.components.pvpc_hourly_pricing
aiopvpc==4.2.2 aiopvpc==4.2.2

View File

@ -67,7 +67,7 @@
"posKind1": 1, "posKind1": 1,
"position1": 0, "position1": 0,
"posKind2": 3, "posKind2": 3,
"position3": 0 "position2": 0
}, },
"name_unicode": "Family Centre", "name_unicode": "Family Centre",
"shade_api_class": "ShadeBottomUpTiltOnClosed180" "shade_api_class": "ShadeBottomUpTiltOnClosed180"
@ -102,7 +102,7 @@
"posKind1": 1, "posKind1": 1,
"position1": 0, "position1": 0,
"posKind2": 3, "posKind2": 3,
"position3": 0 "position2": 0
}, },
"name_unicode": "Family Right", "name_unicode": "Family Right",
"shade_api_class": "ShadeBottomUpTiltOnClosed90" "shade_api_class": "ShadeBottomUpTiltOnClosed90"
@ -137,7 +137,7 @@
"posKind1": 1, "posKind1": 1,
"position1": 0, "position1": 0,
"posKind2": 3, "posKind2": 3,
"position3": 0 "position2": 0
}, },
"name_unicode": "Bed 2", "name_unicode": "Bed 2",
"shade_api_class": "ShadeBottomUpTiltAnywhere" "shade_api_class": "ShadeBottomUpTiltAnywhere"

View File

@ -310,5 +310,31 @@
"bleName": "R23:E63C", "bleName": "R23:E63C",
"shadeGroupIds": [], "shadeGroupIds": [],
"shade_api_class": "ShadeDualOverlappedTilt180" "shade_api_class": "ShadeDualOverlappedTilt180"
},
{
"batteryStatus": null,
"bleName": "AUR:881C",
"capabilities": 11,
"firmware": {
"build": 400,
"revision": 3,
"subRevision": 0
},
"id": 109,
"motion": null,
"name": "Q2VudGVy",
"positions": {
"light": null,
"primary": null,
"secondary": null,
"tilt": null,
"velocity": null
},
"powerType": 12,
"ptName": "Center",
"roomId": 9,
"shadeGroupIds": [],
"type": 95,
"shade_api_class": "None"
} }
] ]