Handle exceptions from PyViCare library (#28536)

* ViCare: Handle exceptions from PyViCare library (#28072)

Sometimes Viessmann server failures or other connection problems may
lead to exceptions thrown when updating data.

This commit handles those exceptions with some error logging and
makes sure that the component does not break completely in that case.

* Remove unneeded returns

* Remove unneeded returns
This commit is contained in:
Hans Oischinger 2019-11-06 22:46:18 +01:00 committed by Martin Hjelmare
parent bb37bc32e3
commit 3d2ff841d3
2 changed files with 70 additions and 48 deletions

View file

@ -1,5 +1,7 @@
"""Viessmann ViCare climate device."""
import logging
import requests
import simplejson
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
@ -111,6 +113,7 @@ class ViCareClimate(ClimateDevice):
def update(self):
"""Let HA know there has been an update from the ViCare API."""
try:
_room_temperature = self._api.getRoomTemperature()
_supply_temperature = self._api.getSupplyTemperature()
if _room_temperature is not None and _room_temperature != PYVICARE_ERROR:
@ -154,12 +157,20 @@ class ViCareClimate(ClimateDevice):
self._current_action = self._api.getBurnerActive()
self._attributes["burner_modulation"] = self._api.getBurnerModulation()
self._attributes["boiler_temperature"] = self._api.getBoilerTemperature()
self._attributes[
"boiler_temperature"
] = self._api.getBoilerTemperature()
elif self._heating_type == HeatingType.heatpump:
self._current_action = self._api.getCompressorActive()
self._attributes["return_temperature"] = self._api.getReturnTemperature()
self._attributes[
"return_temperature"
] = self._api.getReturnTemperature()
except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server")
except simplejson.errors.JSONDecodeError:
_LOGGER.error("Unable to decode data from ViCare server")
@property
def supported_features(self):

View file

@ -1,5 +1,7 @@
"""Viessmann ViCare water_heater device."""
import logging
import requests
import simplejson
from homeassistant.components.water_heater import (
SUPPORT_TARGET_TEMPERATURE,
@ -41,6 +43,8 @@ HA_TO_VICARE_HVAC_DHW = {
OPERATION_MODE_ON: VICARE_MODE_DHW,
}
PYVICARE_ERROR = "error"
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Create the ViCare water_heater devices."""
@ -75,15 +79,22 @@ class ViCareWater(WaterHeaterDevice):
def update(self):
"""Let HA know there has been an update from the ViCare API."""
try:
current_temperature = self._api.getDomesticHotWaterStorageTemperature()
if current_temperature is not None and current_temperature != "error":
if current_temperature != PYVICARE_ERROR:
self._current_temperature = current_temperature
else:
self._current_temperature = None
self._target_temperature = self._api.getDomesticHotWaterConfiguredTemperature()
self._target_temperature = (
self._api.getDomesticHotWaterConfiguredTemperature()
)
self._current_mode = self._api.getActiveMode()
except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server")
except simplejson.errors.JSONDecodeError:
_LOGGER.error("Unable to decode data from ViCare server")
@property
def supported_features(self):