Improve setup retry logic to handle inconsistent powerview hub availability (#38249)

This commit is contained in:
J. Nick Koston 2020-07-26 17:01:29 -10:00 committed by GitHub
parent 2b0914994d
commit 56186a3d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View File

@ -112,21 +112,29 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
try: try:
async with async_timeout.timeout(10): async with async_timeout.timeout(10):
device_info = await async_get_device_info(pv_request) device_info = await async_get_device_info(pv_request)
except HUB_EXCEPTIONS:
_LOGGER.error("Connection error to PowerView hub: %s", hub_address)
raise ConfigEntryNotReady
if not device_info:
_LOGGER.error("Unable to initialize PowerView hub: %s", hub_address)
raise ConfigEntryNotReady
async with async_timeout.timeout(10):
rooms = Rooms(pv_request) rooms = Rooms(pv_request)
room_data = _async_map_data_by_id((await rooms.get_resources())[ROOM_DATA]) room_data = _async_map_data_by_id((await rooms.get_resources())[ROOM_DATA])
async with async_timeout.timeout(10):
scenes = Scenes(pv_request) scenes = Scenes(pv_request)
scene_data = _async_map_data_by_id((await scenes.get_resources())[SCENE_DATA]) scene_data = _async_map_data_by_id(
(await scenes.get_resources())[SCENE_DATA]
)
async with async_timeout.timeout(10):
shades = Shades(pv_request) shades = Shades(pv_request)
shade_data = _async_map_data_by_id((await shades.get_resources())[SHADE_DATA]) shade_data = _async_map_data_by_id(
(await shades.get_resources())[SHADE_DATA]
)
except HUB_EXCEPTIONS:
_LOGGER.error("Connection error to PowerView hub: %s", hub_address)
raise ConfigEntryNotReady
if not device_info:
_LOGGER.error("Unable to initialize PowerView hub: %s", hub_address)
raise ConfigEntryNotReady
async def async_update_data(): async def async_update_data():
"""Fetch data from shade endpoint.""" """Fetch data from shade endpoint."""

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
from aiohttp.client_exceptions import ServerDisconnectedError
from aiopvapi.helpers.aiorequest import PvApiConnectionError from aiopvapi.helpers.aiorequest import PvApiConnectionError
DOMAIN = "hunterdouglas_powerview" DOMAIN = "hunterdouglas_powerview"
@ -64,7 +65,7 @@ PV_SHADE_DATA = "pv_shade_data"
PV_ROOM_DATA = "pv_room_data" PV_ROOM_DATA = "pv_room_data"
COORDINATOR = "coordinator" COORDINATOR = "coordinator"
HUB_EXCEPTIONS = (asyncio.TimeoutError, PvApiConnectionError) HUB_EXCEPTIONS = (ServerDisconnectedError, asyncio.TimeoutError, PvApiConnectionError)
LEGACY_DEVICE_SUB_REVISION = 1 LEGACY_DEVICE_SUB_REVISION = 1
LEGACY_DEVICE_REVISION = 0 LEGACY_DEVICE_REVISION = 0