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

@ -9,6 +9,7 @@ from PyViCare.PyViCareHeatPump import HeatPump
import voluptuous as vol import voluptuous as vol
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID,
CONF_NAME, CONF_NAME,
CONF_PASSWORD, CONF_PASSWORD,
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
@ -23,7 +24,6 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS = ["climate", "sensor", "binary_sensor", "water_heater"] PLATFORMS = ["climate", "sensor", "binary_sensor", "water_heater"]
DOMAIN = "vicare" DOMAIN = "vicare"
PYVICARE_ERROR = "error"
VICARE_API = "api" VICARE_API = "api"
VICARE_NAME = "name" VICARE_NAME = "name"
VICARE_HEATING_TYPE = "heating_type" VICARE_HEATING_TYPE = "heating_type"
@ -48,6 +48,7 @@ CONFIG_SCHEMA = vol.Schema(
{ {
vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string, vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=60): vol.All( vol.Optional(CONF_SCAN_INTERVAL, default=60): vol.All(
cv.time_period, lambda value: value.total_seconds() cv.time_period, lambda value: value.total_seconds()
), ),
@ -71,7 +72,7 @@ def setup(hass, config):
params["circuit"] = conf[CONF_CIRCUIT] params["circuit"] = conf[CONF_CIRCUIT]
params["cacheDuration"] = conf.get(CONF_SCAN_INTERVAL) params["cacheDuration"] = conf.get(CONF_SCAN_INTERVAL)
params["client_id"] = conf.get(CONF_CLIENT_ID)
heating_type = conf[CONF_HEATING_TYPE] heating_type = conf[CONF_HEATING_TYPE]
try: try:

View file

@ -1,6 +1,8 @@
"""Viessmann ViCare sensor device.""" """Viessmann ViCare sensor device."""
from contextlib import suppress
import logging import logging
from PyViCare.PyViCare import PyViCareNotSupportedFeatureError, PyViCareRateLimitError
import requests import requests
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
@ -11,7 +13,6 @@ from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
from . import ( from . import (
DOMAIN as VICARE_DOMAIN, DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API, VICARE_API,
VICARE_HEATING_TYPE, VICARE_HEATING_TYPE,
VICARE_NAME, VICARE_NAME,
@ -29,10 +30,6 @@ SENSOR_BURNER_ACTIVE = "burner_active"
# heatpump sensors # heatpump sensors
SENSOR_COMPRESSOR_ACTIVE = "compressor_active" SENSOR_COMPRESSOR_ACTIVE = "compressor_active"
SENSOR_HEATINGROD_OVERALL = "heatingrod_overall"
SENSOR_HEATINGROD_LEVEL1 = "heatingrod_level1"
SENSOR_HEATINGROD_LEVEL2 = "heatingrod_level2"
SENSOR_HEATINGROD_LEVEL3 = "heatingrod_level3"
SENSOR_TYPES = { SENSOR_TYPES = {
SENSOR_CIRCULATION_PUMP_ACTIVE: { SENSOR_CIRCULATION_PUMP_ACTIVE: {
@ -52,26 +49,6 @@ SENSOR_TYPES = {
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER, CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
CONF_GETTER: lambda api: api.getCompressorActive(), CONF_GETTER: lambda api: api.getCompressorActive(),
}, },
SENSOR_HEATINGROD_OVERALL: {
CONF_NAME: "Heating rod overall",
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
CONF_GETTER: lambda api: api.getHeatingRodStatusOverall(),
},
SENSOR_HEATINGROD_LEVEL1: {
CONF_NAME: "Heating rod level 1",
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
CONF_GETTER: lambda api: api.getHeatingRodStatusLevel1(),
},
SENSOR_HEATINGROD_LEVEL2: {
CONF_NAME: "Heating rod level 2",
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
CONF_GETTER: lambda api: api.getHeatingRodStatusLevel2(),
},
SENSOR_HEATINGROD_LEVEL3: {
CONF_NAME: "Heating rod level 3",
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
CONF_GETTER: lambda api: api.getHeatingRodStatusLevel3(),
},
} }
SENSORS_GENERIC = [SENSOR_CIRCULATION_PUMP_ACTIVE] SENSORS_GENERIC = [SENSOR_CIRCULATION_PUMP_ACTIVE]
@ -80,10 +57,6 @@ SENSORS_BY_HEATINGTYPE = {
HeatingType.gas: [SENSOR_BURNER_ACTIVE], HeatingType.gas: [SENSOR_BURNER_ACTIVE],
HeatingType.heatpump: [ HeatingType.heatpump: [
SENSOR_COMPRESSOR_ACTIVE, SENSOR_COMPRESSOR_ACTIVE,
SENSOR_HEATINGROD_OVERALL,
SENSOR_HEATINGROD_LEVEL1,
SENSOR_HEATINGROD_LEVEL2,
SENSOR_HEATINGROD_LEVEL3,
], ],
HeatingType.fuelcell: [SENSOR_BURNER_ACTIVE], HeatingType.fuelcell: [SENSOR_BURNER_ACTIVE],
} }
@ -126,7 +99,7 @@ class ViCareBinarySensor(BinarySensorEntity):
@property @property
def available(self): def available(self):
"""Return True if entity is available.""" """Return True if entity is available."""
return self._state is not None and self._state != PYVICARE_ERROR return self._state is not None
@property @property
def unique_id(self): def unique_id(self):
@ -151,8 +124,11 @@ class ViCareBinarySensor(BinarySensorEntity):
def update(self): def update(self):
"""Update state of sensor.""" """Update state of sensor."""
try: try:
self._state = self._sensor[CONF_GETTER](self._api) with suppress(PyViCareNotSupportedFeatureError):
self._state = self._sensor[CONF_GETTER](self._api)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server") _LOGGER.error("Unable to retrieve data from ViCare server")
except ValueError: except ValueError:
_LOGGER.error("Unable to decode data from ViCare server") _LOGGER.error("Unable to decode data from ViCare server")
except PyViCareRateLimitError as limit_exception:
_LOGGER.error("Vicare API rate limit exceeded: %s", limit_exception)

View file

@ -1,6 +1,8 @@
"""Viessmann ViCare climate device.""" """Viessmann ViCare climate device."""
from contextlib import suppress
import logging import logging
from PyViCare.PyViCare import PyViCareNotSupportedFeatureError, PyViCareRateLimitError
import requests import requests
import voluptuous as vol import voluptuous as vol
@ -21,7 +23,6 @@ from homeassistant.helpers import entity_platform
from . import ( from . import (
DOMAIN as VICARE_DOMAIN, DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API, VICARE_API,
VICARE_HEATING_TYPE, VICARE_HEATING_TYPE,
VICARE_NAME, VICARE_NAME,
@ -136,47 +137,58 @@ class ViCareClimate(ClimateEntity):
def update(self): def update(self):
"""Let HA know there has been an update from the ViCare API.""" """Let HA know there has been an update from the ViCare API."""
try: try:
_room_temperature = self._api.getRoomTemperature() _room_temperature = None
_supply_temperature = self._api.getSupplyTemperature() with suppress(PyViCareNotSupportedFeatureError):
if _room_temperature is not None and _room_temperature != PYVICARE_ERROR: _room_temperature = self._api.getRoomTemperature()
_supply_temperature = None
with suppress(PyViCareNotSupportedFeatureError):
_supply_temperature = self._api.getSupplyTemperature()
if _room_temperature is not None:
self._current_temperature = _room_temperature self._current_temperature = _room_temperature
elif _supply_temperature != PYVICARE_ERROR: elif _supply_temperature is not None:
self._current_temperature = _supply_temperature self._current_temperature = _supply_temperature
else: else:
self._current_temperature = None self._current_temperature = None
self._current_program = self._api.getActiveProgram()
# The getCurrentDesiredTemperature call can yield 'error' (str) when the system is in standby with suppress(PyViCareNotSupportedFeatureError):
desired_temperature = self._api.getCurrentDesiredTemperature() self._current_program = self._api.getActiveProgram()
if desired_temperature == PYVICARE_ERROR:
desired_temperature = None
self._target_temperature = desired_temperature with suppress(PyViCareNotSupportedFeatureError):
self._target_temperature = self._api.getCurrentDesiredTemperature()
self._current_mode = self._api.getActiveMode() with suppress(PyViCareNotSupportedFeatureError):
self._current_mode = self._api.getActiveMode()
# Update the generic device attributes # Update the generic device attributes
self._attributes = {} self._attributes = {}
self._attributes["room_temperature"] = _room_temperature self._attributes["room_temperature"] = _room_temperature
self._attributes["active_vicare_program"] = self._current_program self._attributes["active_vicare_program"] = self._current_program
self._attributes["active_vicare_mode"] = self._current_mode self._attributes["active_vicare_mode"] = self._current_mode
self._attributes["heating_curve_slope"] = self._api.getHeatingCurveSlope()
self._attributes["heating_curve_shift"] = self._api.getHeatingCurveShift() with suppress(PyViCareNotSupportedFeatureError):
self._attributes[ self._attributes[
"month_since_last_service" "heating_curve_slope"
] = self._api.getMonthSinceLastService() ] = self._api.getHeatingCurveSlope()
self._attributes["date_last_service"] = self._api.getLastServiceDate()
self._attributes["error_history"] = self._api.getErrorHistory() with suppress(PyViCareNotSupportedFeatureError):
self._attributes["active_error"] = self._api.getActiveError() self._attributes[
"heating_curve_shift"
] = self._api.getHeatingCurveShift()
# Update the specific device attributes # Update the specific device attributes
if self._heating_type == HeatingType.gas: if self._heating_type == HeatingType.gas:
self._current_action = self._api.getBurnerActive() with suppress(PyViCareNotSupportedFeatureError):
self._current_action = self._api.getBurnerActive()
elif self._heating_type == HeatingType.heatpump: elif self._heating_type == HeatingType.heatpump:
self._current_action = self._api.getCompressorActive() with suppress(PyViCareNotSupportedFeatureError):
self._current_action = self._api.getCompressorActive()
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server") _LOGGER.error("Unable to retrieve data from ViCare server")
except PyViCareRateLimitError as limit_exception:
_LOGGER.error("Vicare API rate limit exceeded: %s", limit_exception)
except ValueError: except ValueError:
_LOGGER.error("Unable to decode data from ViCare server") _LOGGER.error("Unable to decode data from ViCare server")

View file

@ -3,6 +3,6 @@
"name": "Viessmann ViCare", "name": "Viessmann ViCare",
"documentation": "https://www.home-assistant.io/integrations/vicare", "documentation": "https://www.home-assistant.io/integrations/vicare",
"codeowners": ["@oischinger"], "codeowners": ["@oischinger"],
"requirements": ["PyViCare==0.2.5"], "requirements": ["PyViCare==1.0.0"],
"iot_class": "cloud_polling" "iot_class": "cloud_polling"
} }

View file

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

View file

@ -1,6 +1,8 @@
"""Viessmann ViCare water_heater device.""" """Viessmann ViCare water_heater device."""
from contextlib import suppress
import logging import logging
from PyViCare.PyViCare import PyViCareNotSupportedFeatureError, PyViCareRateLimitError
import requests import requests
from homeassistant.components.water_heater import ( from homeassistant.components.water_heater import (
@ -9,13 +11,7 @@ from homeassistant.components.water_heater import (
) )
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from . import ( from . import DOMAIN as VICARE_DOMAIN, VICARE_API, VICARE_HEATING_TYPE, VICARE_NAME
DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API,
VICARE_HEATING_TYPE,
VICARE_NAME,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -81,19 +77,23 @@ class ViCareWater(WaterHeaterEntity):
def update(self): def update(self):
"""Let HA know there has been an update from the ViCare API.""" """Let HA know there has been an update from the ViCare API."""
try: try:
current_temperature = self._api.getDomesticHotWaterStorageTemperature() with suppress(PyViCareNotSupportedFeatureError):
if current_temperature != PYVICARE_ERROR: self._current_temperature = (
self._current_temperature = current_temperature self._api.getDomesticHotWaterStorageTemperature()
else: )
self._current_temperature = None
self._target_temperature = ( with suppress(PyViCareNotSupportedFeatureError):
self._api.getDomesticHotWaterConfiguredTemperature() self._target_temperature = (
) self._api.getDomesticHotWaterConfiguredTemperature()
)
with suppress(PyViCareNotSupportedFeatureError):
self._current_mode = self._api.getActiveMode()
self._current_mode = self._api.getActiveMode()
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server") _LOGGER.error("Unable to retrieve data from ViCare server")
except PyViCareRateLimitError as limit_exception:
_LOGGER.error("Vicare API rate limit exceeded: %s", limit_exception)
except ValueError: except ValueError:
_LOGGER.error("Unable to decode data from ViCare server") _LOGGER.error("Unable to decode data from ViCare server")

View file

@ -61,7 +61,7 @@ PyTransportNSW==0.1.1
PyTurboJPEG==1.5.0 PyTurboJPEG==1.5.0
# homeassistant.components.vicare # homeassistant.components.vicare
PyViCare==0.2.5 PyViCare==1.0.0
# homeassistant.components.xiaomi_aqara # homeassistant.components.xiaomi_aqara
PyXiaomiGateway==0.13.4 PyXiaomiGateway==0.13.4