Improve error handling of powerview hub maintenance, remove invalid device classes (#73395)

This commit is contained in:
kingy444 2022-06-13 12:26:38 +10:00 committed by GitHub
parent 5854dfa84f
commit 9ae713f128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -7,11 +7,7 @@ from typing import Any, Final
from aiopvapi.resources.shade import BaseShade, factory as PvShade
from homeassistant.components.button import (
ButtonDeviceClass,
ButtonEntity,
ButtonEntityDescription,
)
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
@ -50,7 +46,6 @@ BUTTONS: Final = [
key="calibrate",
name="Calibrate",
icon="mdi:swap-vertical-circle-outline",
device_class=ButtonDeviceClass.UPDATE,
entity_category=EntityCategory.DIAGNOSTIC,
press_action=lambda shade: shade.calibrate(),
),
@ -58,7 +53,6 @@ BUTTONS: Final = [
key="identify",
name="Identify",
icon="mdi:crosshairs-question",
device_class=ButtonDeviceClass.UPDATE,
entity_category=EntityCategory.DIAGNOSTIC,
press_action=lambda shade: shade.jog(),
),

View File

@ -36,9 +36,19 @@ class PowerviewShadeUpdateCoordinator(DataUpdateCoordinator[PowerviewShadeData])
async def _async_update_data(self) -> PowerviewShadeData:
"""Fetch data from shade endpoint."""
async with async_timeout.timeout(10):
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:
raise UpdateFailed("Failed to fetch new shade data")
# only update if shade_entries is valid
self.data.store_group_data(shade_entries[SHADE_DATA])
return self.data