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

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.binary_sensor import (
@ -11,7 +13,6 @@ from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
from . import (
DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API,
VICARE_HEATING_TYPE,
VICARE_NAME,
@ -29,10 +30,6 @@ SENSOR_BURNER_ACTIVE = "burner_active"
# heatpump sensors
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_CIRCULATION_PUMP_ACTIVE: {
@ -52,26 +49,6 @@ SENSOR_TYPES = {
CONF_DEVICE_CLASS: DEVICE_CLASS_POWER,
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]
@ -80,10 +57,6 @@ SENSORS_BY_HEATINGTYPE = {
HeatingType.gas: [SENSOR_BURNER_ACTIVE],
HeatingType.heatpump: [
SENSOR_COMPRESSOR_ACTIVE,
SENSOR_HEATINGROD_OVERALL,
SENSOR_HEATINGROD_LEVEL1,
SENSOR_HEATINGROD_LEVEL2,
SENSOR_HEATINGROD_LEVEL3,
],
HeatingType.fuelcell: [SENSOR_BURNER_ACTIVE],
}
@ -126,7 +99,7 @@ class ViCareBinarySensor(BinarySensorEntity):
@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):
@ -151,8 +124,11 @@ class ViCareBinarySensor(BinarySensorEntity):
def update(self):
"""Update state of sensor."""
try:
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)

View file

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

View file

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

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:
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)

View file

@ -1,6 +1,8 @@
"""Viessmann ViCare water_heater device."""
from contextlib import suppress
import logging
from PyViCare.PyViCare import PyViCareNotSupportedFeatureError, PyViCareRateLimitError
import requests
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 . import (
DOMAIN as VICARE_DOMAIN,
PYVICARE_ERROR,
VICARE_API,
VICARE_HEATING_TYPE,
VICARE_NAME,
)
from . import DOMAIN as VICARE_DOMAIN, VICARE_API, VICARE_HEATING_TYPE, VICARE_NAME
_LOGGER = logging.getLogger(__name__)
@ -81,19 +77,23 @@ class ViCareWater(WaterHeaterEntity):
def update(self):
"""Let HA know there has been an update from the ViCare API."""
try:
current_temperature = self._api.getDomesticHotWaterStorageTemperature()
if current_temperature != PYVICARE_ERROR:
self._current_temperature = current_temperature
else:
self._current_temperature = None
with suppress(PyViCareNotSupportedFeatureError):
self._current_temperature = (
self._api.getDomesticHotWaterStorageTemperature()
)
with suppress(PyViCareNotSupportedFeatureError):
self._target_temperature = (
self._api.getDomesticHotWaterConfiguredTemperature()
)
with suppress(PyViCareNotSupportedFeatureError):
self._current_mode = self._api.getActiveMode()
except requests.exceptions.ConnectionError:
_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:
_LOGGER.error("Unable to decode data from ViCare server")

View file

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