From 738d00fb05515265865a7e0b984c9ecaf7b2f82c Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Tue, 23 Jul 2019 23:32:48 +0200 Subject: [PATCH] Increase vallox robustness on startup (#25382) * Vallox: Increase robustness on startup Experiments showed that timing of websocket requests to the Vallox firmware is critical when fetching new metrics. Tests on different Raspberry Pis and x86 machines showed that those machines with little processing power tend to fail the timing requirments during the busy startup phase of Home Assistant, resulting in the Vallox integration failing to set itself up. This patch catches Websocket's InvalidMessage, which is a symptom of failing the timing requirements. Experiments again showed that on the Raspberry's, this exception is catched once at startup, but the integration is running fine afterwards. * Update __init__.py * Bump to new 2.1.0 version of api. * Bump to api 2.2.0 --- homeassistant/components/vallox/__init__.py | 21 ++++++++++++------- homeassistant/components/vallox/fan.py | 2 +- homeassistant/components/vallox/manifest.json | 2 +- homeassistant/components/vallox/sensor.py | 2 +- requirements_all.txt | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/vallox/__init__.py b/homeassistant/components/vallox/__init__.py index ebb1d56cf51..1c8bef1e3d1 100644 --- a/homeassistant/components/vallox/__init__.py +++ b/homeassistant/components/vallox/__init__.py @@ -6,6 +6,7 @@ import logging from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox from vallox_websocket_api.constants import vlxDevConstants +from vallox_websocket_api.exceptions import ValloxApiException import voluptuous as vol from homeassistant.const import CONF_HOST, CONF_NAME @@ -110,9 +111,13 @@ async def async_setup(hass, config): service_handler.async_handle, schema=schema) - # Fetch initial state once before bringing up the platforms. - await state_proxy.async_update(None) - + # The vallox hardware expects quite strict timings for websocket + # requests. Timings that machines with less processing power, like + # Raspberries, cannot live up to during the busy start phase of Home + # Asssistant. Hence, async_add_entities() for fan and sensor in respective + # code will be called with update_before_add=False to intentionally delay + # the first request, increasing chance that it is issued only when the + # machine is less busy again. hass.async_create_task( async_load_platform(hass, 'sensor', DOMAIN, {}, config)) hass.async_create_task( @@ -164,7 +169,7 @@ class ValloxStateProxy: self._profile = await self._client.get_profile() self._valid = True - except OSError as err: + except (OSError, ValloxApiException) as err: _LOGGER.error("Error during state cache update: %s", err) self._valid = False @@ -187,7 +192,7 @@ class ValloxServiceHandler: await self._client.set_profile(STR_TO_PROFILE[profile]) return True - except OSError as err: + except (OSError, ValloxApiException) as err: _LOGGER.error("Error setting ventilation profile: %s", err) return False @@ -201,7 +206,7 @@ class ValloxServiceHandler: {METRIC_KEY_PROFILE_FAN_SPEED_HOME: fan_speed}) return True - except OSError as err: + except (OSError, ValloxApiException) as err: _LOGGER.error("Error setting fan speed for Home profile: %s", err) return False @@ -215,7 +220,7 @@ class ValloxServiceHandler: {METRIC_KEY_PROFILE_FAN_SPEED_AWAY: fan_speed}) return True - except OSError as err: + except (OSError, ValloxApiException) as err: _LOGGER.error("Error setting fan speed for Away profile: %s", err) return False @@ -229,7 +234,7 @@ class ValloxServiceHandler: {METRIC_KEY_PROFILE_FAN_SPEED_BOOST: fan_speed}) return True - except OSError as err: + except (OSError, ValloxApiException) as err: _LOGGER.error("Error setting fan speed for Boost profile: %s", err) return False diff --git a/homeassistant/components/vallox/fan.py b/homeassistant/components/vallox/fan.py index 483d5649c76..bc51e0be61a 100644 --- a/homeassistant/components/vallox/fan.py +++ b/homeassistant/components/vallox/fan.py @@ -42,7 +42,7 @@ async def async_setup_platform(hass, config, async_add_entities, client, hass.data[DOMAIN]['state_proxy']) - async_add_entities([device], update_before_add=True) + async_add_entities([device], update_before_add=False) class ValloxFan(FanEntity): diff --git a/homeassistant/components/vallox/manifest.json b/homeassistant/components/vallox/manifest.json index 1f3042342d5..4f9b0f4d126 100644 --- a/homeassistant/components/vallox/manifest.json +++ b/homeassistant/components/vallox/manifest.json @@ -3,7 +3,7 @@ "name": "Vallox", "documentation": "https://www.home-assistant.io/components/vallox", "requirements": [ - "vallox-websocket-api==2.0.0" + "vallox-websocket-api==2.2.0" ], "dependencies": [], "codeowners": [] diff --git a/homeassistant/components/vallox/sensor.py b/homeassistant/components/vallox/sensor.py index 416d068f9bf..5348c84049e 100644 --- a/homeassistant/components/vallox/sensor.py +++ b/homeassistant/components/vallox/sensor.py @@ -90,7 +90,7 @@ async def async_setup_platform(hass, config, async_add_entities, ), ] - async_add_entities(sensors, update_before_add=True) + async_add_entities(sensors, update_before_add=False) class ValloxSensor(Entity): diff --git a/requirements_all.txt b/requirements_all.txt index 3059ac6ed51..d7f64453b33 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1855,7 +1855,7 @@ uscisstatus==0.1.1 uvcclient==0.11.0 # homeassistant.components.vallox -vallox-websocket-api==2.0.0 +vallox-websocket-api==2.2.0 # homeassistant.components.venstar venstarcolortouch==0.7