Update to PyVicare 1.0 (#53281)

This commit is contained in:
Hans Oischinger 2021-07-22 21:56:38 +02:00 committed by GitHub
parent 0b71055989
commit 84dc6af760
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 77 deletions

View file

@ -1,6 +1,8 @@
"""Viessmann ViCare sensor device."""
from contextlib import suppress
import logging
from PyViCare.PyViCare import PyViCareNotSupportedFeatureError, PyViCareRateLimitError
import requests
from homeassistant.components.sensor import SensorEntity
@ -21,7 +23,6 @@ from homeassistant.const import (
from . import (
DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API,
VICARE_HEATING_TYPE,
VICARE_NAME,
@ -350,7 +351,7 @@ class ViCareSensor(SensorEntity):
@property
def available(self):
"""Return True if entity is available."""
return self._state is not None and self._state != PYVICARE_ERROR
return self._state is not None
@property
def unique_id(self):
@ -385,8 +386,11 @@ class ViCareSensor(SensorEntity):
def update(self):
"""Update state of sensor."""
try:
self._state = self._sensor[CONF_GETTER](self._api)
with suppress(PyViCareNotSupportedFeatureError):
self._state = self._sensor[CONF_GETTER](self._api)
except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server")
except ValueError:
_LOGGER.error("Unable to decode data from ViCare server")
except PyViCareRateLimitError as limit_exception:
_LOGGER.error("Vicare API rate limit exceeded: %s", limit_exception)