From e9c69682c7f90ad2b19c1941d83b2de627c83056 Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Thu, 23 Dec 2021 07:48:31 +0100 Subject: [PATCH] Fix broken Vallox integration in 2021.12 (#62308) --- homeassistant/components/vallox/__init__.py | 23 +++++++++++++++++++-- homeassistant/components/vallox/const.py | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/vallox/__init__.py b/homeassistant/components/vallox/__init__.py index 73dc633834e..9beddaaad66 100644 --- a/homeassistant/components/vallox/__init__.py +++ b/homeassistant/components/vallox/__init__.py @@ -1,6 +1,7 @@ """Support for Vallox ventilation units.""" from __future__ import annotations +import asyncio from dataclasses import dataclass, field import ipaddress import logging @@ -13,7 +14,7 @@ from vallox_websocket_api.vallox import get_uuid as calculate_uuid import voluptuous as vol from homeassistant.const import CONF_HOST, CONF_NAME, EVENT_HOMEASSISTANT_STARTED -from homeassistant.core import HomeAssistant, ServiceCall +from homeassistant.core import CoreState, HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.typing import ConfigType, StateType @@ -25,6 +26,7 @@ from .const import ( DEFAULT_FAN_SPEED_HOME, DEFAULT_NAME, DOMAIN, + INITIAL_COORDINATOR_UPDATE_RETRY_INTERVAL_SECONDS, METRIC_KEY_PROFILE_FAN_SPEED_AWAY, METRIC_KEY_PROFILE_FAN_SPEED_BOOST, METRIC_KEY_PROFILE_FAN_SPEED_HOME, @@ -171,7 +173,24 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.data[DOMAIN] = {"client": client, "coordinator": coordinator, "name": name} async def _async_load_platform_delayed(*_: Any) -> None: - await coordinator.async_refresh() + # We need a successful update before loading the platforms, because platform init code + # derives the UUIDs from the data the coordinator fetches. + warned_once = False + while hass.state == CoreState.running: + await coordinator.async_refresh() + if coordinator.last_update_success: + break + + if not warned_once: + _LOGGER.warning( + "Vallox integration not ready yet; Retrying in background" + ) + warned_once = True + + await asyncio.sleep(INITIAL_COORDINATOR_UPDATE_RETRY_INTERVAL_SECONDS) + else: + return + hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config)) hass.async_create_task(async_load_platform(hass, "fan", DOMAIN, {}, config)) diff --git a/homeassistant/components/vallox/const.py b/homeassistant/components/vallox/const.py index aba10188bde..96767bd0e18 100644 --- a/homeassistant/components/vallox/const.py +++ b/homeassistant/components/vallox/const.py @@ -7,6 +7,7 @@ from vallox_websocket_api import PROFILE as VALLOX_PROFILE DOMAIN = "vallox" DEFAULT_NAME = "Vallox" +INITIAL_COORDINATOR_UPDATE_RETRY_INTERVAL_SECONDS = 5 STATE_SCAN_INTERVAL = timedelta(seconds=60) # Common metric keys and (default) values.