mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +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."""
|
"""The Hunter Douglas PowerView integration."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiopvapi.helpers.aiorequest import AioRequest
|
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
|
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)
|
|
||||||
except HUB_EXCEPTIONS as err:
|
except HUB_EXCEPTIONS as err:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
f"Connection error to PowerView hub {hub_address}: {err}"
|
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
|
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:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
f"Connection error to PowerView hub {hub_address}: {err}"
|
f"Connection error to PowerView hub {hub_address}: {err}"
|
||||||
|
@ -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,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)
|
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)
|
|
||||||
except HUB_EXCEPTIONS as err:
|
except HUB_EXCEPTIONS as err:
|
||||||
raise CannotConnect from err
|
raise CannotConnect from err
|
||||||
|
|
||||||
|
@ -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,16 +35,15 @@ 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:
|
# hub is undergoing maintenance, pause polling
|
||||||
# hub is undergoing maintenance, pause polling
|
raise UpdateFailed(error) from error
|
||||||
raise UpdateFailed(error) from error
|
except HUB_EXCEPTIONS as error:
|
||||||
except HUB_EXCEPTIONS as error:
|
raise UpdateFailed(
|
||||||
raise UpdateFailed(
|
f"Powerview Hub {self.hub.hub_address} did not return any data: {error}"
|
||||||
f"Powerview Hub {self.hub.hub_address} did not return any data: {error}"
|
) from error
|
||||||
) from error
|
|
||||||
|
|
||||||
if not shade_entries:
|
if not shade_entries:
|
||||||
raise UpdateFailed("No new shade data was returned")
|
raise UpdateFailed("No new shade data was returned")
|
||||||
|
@ -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):
|
_LOGGER.debug("Initial refresh of shade: %s", shade.name)
|
||||||
# hold off to avoid spamming the hub
|
await shade.refresh(suppress_timeout=True) # default 15 second timeout
|
||||||
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():
|
||||||
@ -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)
|
||||||
|
|
||||||
|
@ -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."]
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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"
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user