mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Move powerview timeout logic to the upstream api (#113984)
This commit is contained in:
parent
efc54971d3
commit
26b6bd83fc
@ -1,6 +1,4 @@
|
||||
"""The Hunter Douglas PowerView integration."""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from aiopvapi.helpers.aiorequest import AioRequest
|
||||
@ -52,11 +50,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hub_address, loop=hass.loop, websession=websession, api_version=api_version
|
||||
)
|
||||
|
||||
# default 15 second timeout for each call in upstream
|
||||
try:
|
||||
async with asyncio.timeout(10):
|
||||
hub = Hub(pv_request)
|
||||
await hub.query_firmware()
|
||||
device_info = await async_get_device_info(hub)
|
||||
hub = Hub(pv_request)
|
||||
await hub.query_firmware()
|
||||
device_info = await async_get_device_info(hub)
|
||||
except HUB_EXCEPTIONS as err:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Connection error to PowerView hub {hub_address}: {err}"
|
||||
@ -75,15 +73,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return False
|
||||
|
||||
try:
|
||||
async with asyncio.timeout(10):
|
||||
rooms = Rooms(pv_request)
|
||||
room_data: PowerviewData = await rooms.get_rooms()
|
||||
async with asyncio.timeout(10):
|
||||
scenes = Scenes(pv_request)
|
||||
scene_data: PowerviewData = await scenes.get_scenes()
|
||||
async with asyncio.timeout(10):
|
||||
shades = Shades(pv_request)
|
||||
shade_data: PowerviewData = await shades.get_shades()
|
||||
rooms = Rooms(pv_request)
|
||||
room_data: PowerviewData = await rooms.get_rooms()
|
||||
|
||||
scenes = Scenes(pv_request)
|
||||
scene_data: PowerviewData = await scenes.get_scenes()
|
||||
|
||||
shades = Shades(pv_request)
|
||||
shade_data: PowerviewData = await shades.get_shades()
|
||||
except HUB_EXCEPTIONS as err:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Connection error to PowerView hub {hub_address}: {err}"
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
@ -38,10 +37,9 @@ async def validate_input(hass: HomeAssistant, hub_address: str) -> dict[str, str
|
||||
pv_request = AioRequest(hub_address, loop=hass.loop, websession=websession)
|
||||
|
||||
try:
|
||||
async with asyncio.timeout(10):
|
||||
hub = Hub(pv_request)
|
||||
await hub.query_firmware()
|
||||
device_info = await async_get_device_info(hub)
|
||||
hub = Hub(pv_request)
|
||||
await hub.query_firmware()
|
||||
device_info = await async_get_device_info(hub)
|
||||
except HUB_EXCEPTIONS as err:
|
||||
raise CannotConnect from err
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
@ -36,16 +35,15 @@ class PowerviewShadeUpdateCoordinator(DataUpdateCoordinator[PowerviewShadeData])
|
||||
async def _async_update_data(self) -> PowerviewShadeData:
|
||||
"""Fetch data from shade endpoint."""
|
||||
|
||||
async with asyncio.timeout(10):
|
||||
try:
|
||||
shade_entries = await self.shades.get_shades()
|
||||
except PvApiMaintenance as error:
|
||||
# hub is undergoing maintenance, pause polling
|
||||
raise UpdateFailed(error) from error
|
||||
except HUB_EXCEPTIONS as error:
|
||||
raise UpdateFailed(
|
||||
f"Powerview Hub {self.hub.hub_address} did not return any data: {error}"
|
||||
) from error
|
||||
try:
|
||||
shade_entries = await self.shades.get_shades()
|
||||
except PvApiMaintenance as error:
|
||||
# hub is undergoing maintenance, pause polling
|
||||
raise UpdateFailed(error) from error
|
||||
except HUB_EXCEPTIONS as error:
|
||||
raise UpdateFailed(
|
||||
f"Powerview Hub {self.hub.hub_address} did not return any data: {error}"
|
||||
) from error
|
||||
|
||||
if not shade_entries:
|
||||
raise UpdateFailed("No new shade data was returned")
|
||||
|
@ -2,9 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable, Iterable
|
||||
from contextlib import suppress
|
||||
from dataclasses import replace
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
@ -68,11 +66,8 @@ async def async_setup_entry(
|
||||
"""
|
||||
|
||||
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()
|
||||
_LOGGER.debug("Initial refresh of shade: %s", shade.name)
|
||||
await shade.refresh(suppress_timeout=True) # default 15 second timeout
|
||||
|
||||
entities: list[ShadeEntity] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
@ -324,9 +319,7 @@ class PowerViewShadeBase(ShadeEntity, CoverEntity):
|
||||
# error if are already have one in flight
|
||||
return
|
||||
# suppress timeouts caused by hub nightly reboot
|
||||
with suppress(TimeoutError):
|
||||
async with asyncio.timeout(10):
|
||||
await self._shade.refresh()
|
||||
await self._shade.refresh(suppress_timeout=True) # default 15 second timeout
|
||||
_LOGGER.debug("Process update %s: %s", self.name, self._shade.current_position)
|
||||
self._async_update_shade_data(self._shade.current_position)
|
||||
|
||||
|
@ -18,6 +18,6 @@
|
||||
},
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["aiopvapi"],
|
||||
"requirements": ["aiopvapi==3.0.2"],
|
||||
"requirements": ["aiopvapi==3.1.1"],
|
||||
"zeroconf": ["_powerview._tcp.local.", "_powerview-g3._tcp.local."]
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ SENSORS: Final = [
|
||||
native_unit_fn=lambda shade: PERCENTAGE,
|
||||
native_value_fn=lambda shade: shade.get_battery_strength(),
|
||||
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(
|
||||
key="signal",
|
||||
@ -72,7 +72,7 @@ SENSORS: Final = [
|
||||
native_unit_fn=get_signal_native_unit,
|
||||
native_value_fn=lambda shade: shade.get_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,
|
||||
),
|
||||
]
|
||||
|
@ -333,7 +333,7 @@ aiopulse==0.4.4
|
||||
aiopurpleair==2022.12.1
|
||||
|
||||
# homeassistant.components.hunterdouglas_powerview
|
||||
aiopvapi==3.0.2
|
||||
aiopvapi==3.1.1
|
||||
|
||||
# homeassistant.components.pvpc_hourly_pricing
|
||||
aiopvpc==4.2.2
|
||||
|
@ -306,7 +306,7 @@ aiopulse==0.4.4
|
||||
aiopurpleair==2022.12.1
|
||||
|
||||
# homeassistant.components.hunterdouglas_powerview
|
||||
aiopvapi==3.0.2
|
||||
aiopvapi==3.1.1
|
||||
|
||||
# homeassistant.components.pvpc_hourly_pricing
|
||||
aiopvpc==4.2.2
|
||||
|
@ -67,7 +67,7 @@
|
||||
"posKind1": 1,
|
||||
"position1": 0,
|
||||
"posKind2": 3,
|
||||
"position3": 0
|
||||
"position2": 0
|
||||
},
|
||||
"name_unicode": "Family Centre",
|
||||
"shade_api_class": "ShadeBottomUpTiltOnClosed180"
|
||||
@ -102,7 +102,7 @@
|
||||
"posKind1": 1,
|
||||
"position1": 0,
|
||||
"posKind2": 3,
|
||||
"position3": 0
|
||||
"position2": 0
|
||||
},
|
||||
"name_unicode": "Family Right",
|
||||
"shade_api_class": "ShadeBottomUpTiltOnClosed90"
|
||||
@ -137,7 +137,7 @@
|
||||
"posKind1": 1,
|
||||
"position1": 0,
|
||||
"posKind2": 3,
|
||||
"position3": 0
|
||||
"position2": 0
|
||||
},
|
||||
"name_unicode": "Bed 2",
|
||||
"shade_api_class": "ShadeBottomUpTiltAnywhere"
|
||||
|
@ -310,5 +310,31 @@
|
||||
"bleName": "R23:E63C",
|
||||
"shadeGroupIds": [],
|
||||
"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"
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user