mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Improve error handling of powerview hub maintenance, remove invalid device classes (#73395)
This commit is contained in:
parent
5854dfa84f
commit
9ae713f128
@ -7,11 +7,7 @@ from typing import Any, Final
|
|||||||
|
|
||||||
from aiopvapi.resources.shade import BaseShade, factory as PvShade
|
from aiopvapi.resources.shade import BaseShade, factory as PvShade
|
||||||
|
|
||||||
from homeassistant.components.button import (
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
ButtonDeviceClass,
|
|
||||||
ButtonEntity,
|
|
||||||
ButtonEntityDescription,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
@ -50,7 +46,6 @@ BUTTONS: Final = [
|
|||||||
key="calibrate",
|
key="calibrate",
|
||||||
name="Calibrate",
|
name="Calibrate",
|
||||||
icon="mdi:swap-vertical-circle-outline",
|
icon="mdi:swap-vertical-circle-outline",
|
||||||
device_class=ButtonDeviceClass.UPDATE,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
press_action=lambda shade: shade.calibrate(),
|
press_action=lambda shade: shade.calibrate(),
|
||||||
),
|
),
|
||||||
@ -58,7 +53,6 @@ BUTTONS: Final = [
|
|||||||
key="identify",
|
key="identify",
|
||||||
name="Identify",
|
name="Identify",
|
||||||
icon="mdi:crosshairs-question",
|
icon="mdi:crosshairs-question",
|
||||||
device_class=ButtonDeviceClass.UPDATE,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
press_action=lambda shade: shade.jog(),
|
press_action=lambda shade: shade.jog(),
|
||||||
),
|
),
|
||||||
|
@ -36,9 +36,19 @@ 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 async_timeout.timeout(10):
|
async with async_timeout.timeout(10):
|
||||||
shade_entries = await self.shades.get_resources()
|
shade_entries = await self.shades.get_resources()
|
||||||
|
|
||||||
|
if isinstance(shade_entries, bool):
|
||||||
|
# hub returns boolean on a 204/423 empty response (maintenance)
|
||||||
|
# continual polling results in inevitable error
|
||||||
|
raise UpdateFailed("Powerview Hub is undergoing maintenance")
|
||||||
|
|
||||||
if not shade_entries:
|
if not shade_entries:
|
||||||
raise UpdateFailed("Failed to fetch new shade data")
|
raise UpdateFailed("Failed to fetch new shade data")
|
||||||
|
|
||||||
|
# only update if shade_entries is valid
|
||||||
self.data.store_group_data(shade_entries[SHADE_DATA])
|
self.data.store_group_data(shade_entries[SHADE_DATA])
|
||||||
|
|
||||||
return self.data
|
return self.data
|
||||||
|
Loading…
x
Reference in New Issue
Block a user