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
This commit is contained in:
Andre Richter 2019-07-23 23:32:48 +02:00 committed by Martin Hjelmare
parent 5ce6ea2df5
commit 738d00fb05
5 changed files with 17 additions and 12 deletions

View file

@ -6,6 +6,7 @@ import logging
from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox from vallox_websocket_api import PROFILE as VALLOX_PROFILE, Vallox
from vallox_websocket_api.constants import vlxDevConstants from vallox_websocket_api.constants import vlxDevConstants
from vallox_websocket_api.exceptions import ValloxApiException
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_NAME from homeassistant.const import CONF_HOST, CONF_NAME
@ -110,9 +111,13 @@ async def async_setup(hass, config):
service_handler.async_handle, service_handler.async_handle,
schema=schema) schema=schema)
# Fetch initial state once before bringing up the platforms. # The vallox hardware expects quite strict timings for websocket
await state_proxy.async_update(None) # 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( hass.async_create_task(
async_load_platform(hass, 'sensor', DOMAIN, {}, config)) async_load_platform(hass, 'sensor', DOMAIN, {}, config))
hass.async_create_task( hass.async_create_task(
@ -164,7 +169,7 @@ class ValloxStateProxy:
self._profile = await self._client.get_profile() self._profile = await self._client.get_profile()
self._valid = True self._valid = True
except OSError as err: except (OSError, ValloxApiException) as err:
_LOGGER.error("Error during state cache update: %s", err) _LOGGER.error("Error during state cache update: %s", err)
self._valid = False self._valid = False
@ -187,7 +192,7 @@ class ValloxServiceHandler:
await self._client.set_profile(STR_TO_PROFILE[profile]) await self._client.set_profile(STR_TO_PROFILE[profile])
return True return True
except OSError as err: except (OSError, ValloxApiException) as err:
_LOGGER.error("Error setting ventilation profile: %s", err) _LOGGER.error("Error setting ventilation profile: %s", err)
return False return False
@ -201,7 +206,7 @@ class ValloxServiceHandler:
{METRIC_KEY_PROFILE_FAN_SPEED_HOME: fan_speed}) {METRIC_KEY_PROFILE_FAN_SPEED_HOME: fan_speed})
return True return True
except OSError as err: except (OSError, ValloxApiException) as err:
_LOGGER.error("Error setting fan speed for Home profile: %s", err) _LOGGER.error("Error setting fan speed for Home profile: %s", err)
return False return False
@ -215,7 +220,7 @@ class ValloxServiceHandler:
{METRIC_KEY_PROFILE_FAN_SPEED_AWAY: fan_speed}) {METRIC_KEY_PROFILE_FAN_SPEED_AWAY: fan_speed})
return True return True
except OSError as err: except (OSError, ValloxApiException) as err:
_LOGGER.error("Error setting fan speed for Away profile: %s", err) _LOGGER.error("Error setting fan speed for Away profile: %s", err)
return False return False
@ -229,7 +234,7 @@ class ValloxServiceHandler:
{METRIC_KEY_PROFILE_FAN_SPEED_BOOST: fan_speed}) {METRIC_KEY_PROFILE_FAN_SPEED_BOOST: fan_speed})
return True return True
except OSError as err: except (OSError, ValloxApiException) as err:
_LOGGER.error("Error setting fan speed for Boost profile: %s", _LOGGER.error("Error setting fan speed for Boost profile: %s",
err) err)
return False return False

View file

@ -42,7 +42,7 @@ async def async_setup_platform(hass, config, async_add_entities,
client, client,
hass.data[DOMAIN]['state_proxy']) hass.data[DOMAIN]['state_proxy'])
async_add_entities([device], update_before_add=True) async_add_entities([device], update_before_add=False)
class ValloxFan(FanEntity): class ValloxFan(FanEntity):

View file

@ -3,7 +3,7 @@
"name": "Vallox", "name": "Vallox",
"documentation": "https://www.home-assistant.io/components/vallox", "documentation": "https://www.home-assistant.io/components/vallox",
"requirements": [ "requirements": [
"vallox-websocket-api==2.0.0" "vallox-websocket-api==2.2.0"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [] "codeowners": []

View file

@ -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): class ValloxSensor(Entity):

View file

@ -1855,7 +1855,7 @@ uscisstatus==0.1.1
uvcclient==0.11.0 uvcclient==0.11.0
# homeassistant.components.vallox # homeassistant.components.vallox
vallox-websocket-api==2.0.0 vallox-websocket-api==2.2.0
# homeassistant.components.venstar # homeassistant.components.venstar
venstarcolortouch==0.7 venstarcolortouch==0.7