diff --git a/homeassistant/components/vicare/__init__.py b/homeassistant/components/vicare/__init__.py index 9fec04f23283f35a335dd53c292a35797547b9e9..e091ff99970a508accba0af953341892e8689685 100644 --- a/homeassistant/components/vicare/__init__.py +++ b/homeassistant/components/vicare/__init__.py @@ -1,8 +1,12 @@ """The ViCare integration.""" +import enum import logging import voluptuous as vol + from PyViCare.PyViCareDevice import Device +from PyViCare.PyViCareGazBoiler import GazBoiler +from PyViCare.PyViCareHeatPump import HeatPump import homeassistant.helpers.config_validation as cv from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_NAME @@ -15,8 +19,20 @@ VICARE_PLATFORMS = ["climate", "water_heater"] DOMAIN = "vicare" VICARE_API = "api" VICARE_NAME = "name" +VICARE_HEATING_TYPE = "heating_type" CONF_CIRCUIT = "circuit" +CONF_HEATING_TYPE = "heating_type" +DEFAULT_HEATING_TYPE = "generic" + + +class HeatingType(enum.Enum): + """Possible options for heating type.""" + + generic = "generic" + gas = "gas" + heatpump = "heatpump" + CONFIG_SCHEMA = vol.Schema( { @@ -26,6 +42,9 @@ CONFIG_SCHEMA = vol.Schema( vol.Required(CONF_PASSWORD): cv.string, vol.Optional(CONF_CIRCUIT): int, vol.Optional(CONF_NAME, default="ViCare"): cv.string, + vol.Optional(CONF_HEATING_TYPE, default=DEFAULT_HEATING_TYPE): cv.enum( + HeatingType + ), } ) }, @@ -40,8 +59,15 @@ def setup(hass, config): if conf.get(CONF_CIRCUIT) is not None: params["circuit"] = conf[CONF_CIRCUIT] + heating_type = conf[CONF_HEATING_TYPE] + try: - vicare_api = Device(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params) + if heating_type == HeatingType.gas: + vicare_api = GazBoiler(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params) + elif heating_type == HeatingType.heatpump: + vicare_api = HeatPump(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params) + else: + vicare_api = Device(conf[CONF_USERNAME], conf[CONF_PASSWORD], **params) except AttributeError: _LOGGER.error( "Failed to create PyViCare API client. Please check your credentials." @@ -51,6 +77,7 @@ def setup(hass, config): hass.data[DOMAIN] = {} hass.data[DOMAIN][VICARE_API] = vicare_api hass.data[DOMAIN][VICARE_NAME] = conf[CONF_NAME] + hass.data[DOMAIN][VICARE_HEATING_TYPE] = heating_type for platform in VICARE_PLATFORMS: discovery.load_platform(hass, platform, DOMAIN, {}, config) diff --git a/homeassistant/components/vicare/climate.py b/homeassistant/components/vicare/climate.py index 0dcb83f758afc8d0203b024684154e5c2f1c4820..fe162c0c837316a3e7038dfaccc8557f631c1a93 100644 --- a/homeassistant/components/vicare/climate.py +++ b/homeassistant/components/vicare/climate.py @@ -10,12 +10,16 @@ from homeassistant.components.climate.const import ( HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_AUTO, + CURRENT_HVAC_HEAT, + CURRENT_HVAC_IDLE, ) from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE, PRECISION_WHOLE from . import DOMAIN as VICARE_DOMAIN from . import VICARE_API from . import VICARE_NAME +from . import VICARE_HEATING_TYPE +from . import HeatingType _LOGGER = logging.getLogger(__name__) @@ -77,15 +81,22 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if discovery_info is None: return vicare_api = hass.data[VICARE_DOMAIN][VICARE_API] + heating_type = hass.data[VICARE_DOMAIN][VICARE_HEATING_TYPE] add_entities( - [ViCareClimate(f"{hass.data[VICARE_DOMAIN][VICARE_NAME]} Heating", vicare_api)] + [ + ViCareClimate( + f"{hass.data[VICARE_DOMAIN][VICARE_NAME]} Heating", + vicare_api, + heating_type, + ) + ] ) class ViCareClimate(ClimateDevice): """Representation of the ViCare heating climate device.""" - def __init__(self, name, api): + def __init__(self, name, api, heating_type): """Initialize the climate device.""" self._name = name self._state = None @@ -95,6 +106,8 @@ class ViCareClimate(ClimateDevice): self._current_mode = None self._current_temperature = None self._current_program = None + self._heating_type = heating_type + self._current_action = None def update(self): """Let HA know there has been an update from the ViCare API.""" @@ -117,7 +130,7 @@ class ViCareClimate(ClimateDevice): self._current_mode = self._api.getActiveMode() - # Update the device attributes + # Update the generic device attributes self._attributes = {} self._attributes["room_temperature"] = _room_temperature self._attributes["supply_temperature"] = _supply_temperature @@ -136,6 +149,18 @@ class ViCareClimate(ClimateDevice): "circulationpump_active" ] = self._api.getCirculationPumpActive() + # Update the specific device attributes + if self._heating_type == HeatingType.gas: + self._current_action = self._api.getBurnerActive() + + self._attributes["burner_modulation"] = self._api.getBurnerModulation() + 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() + @property def supported_features(self): """Return the list of supported features.""" @@ -183,6 +208,13 @@ class ViCareClimate(ClimateDevice): """Return the list of available hvac modes.""" return list(HA_TO_VICARE_HVAC_HEATING) + @property + def hvac_action(self): + """Return the current hvac action.""" + if self._current_action: + return CURRENT_HVAC_HEAT + return CURRENT_HVAC_IDLE + @property def min_temp(self): """Return the minimum temperature.""" diff --git a/homeassistant/components/vicare/manifest.json b/homeassistant/components/vicare/manifest.json index 9f7c703fe4b514befa39ca507b509d9e89142128..03bb16fa9bbcf8a9761ae5ff0a3a7f1e47c7f0d5 100644 --- a/homeassistant/components/vicare/manifest.json +++ b/homeassistant/components/vicare/manifest.json @@ -4,6 +4,6 @@ "documentation": "https://www.home-assistant.io/integrations/vicare", "dependencies": [], "codeowners": ["@oischinger"], - "requirements": ["PyViCare==0.1.1"] + "requirements": ["PyViCare==0.1.2"] } diff --git a/homeassistant/components/vicare/water_heater.py b/homeassistant/components/vicare/water_heater.py index 71c0f6c2aefe7a49358cb1b72f156f5d59147f8f..7c4968ad0a413893cd02720dd8ab5f99f0cd911d 100644 --- a/homeassistant/components/vicare/water_heater.py +++ b/homeassistant/components/vicare/water_heater.py @@ -10,6 +10,7 @@ from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE, PRECISION_WHOLE from . import DOMAIN as VICARE_DOMAIN from . import VICARE_API from . import VICARE_NAME +from . import VICARE_HEATING_TYPE _LOGGER = logging.getLogger(__name__) @@ -46,22 +47,31 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if discovery_info is None: return vicare_api = hass.data[VICARE_DOMAIN][VICARE_API] + heating_type = hass.data[VICARE_DOMAIN][VICARE_HEATING_TYPE] add_entities( - [ViCareWater(f"{hass.data[VICARE_DOMAIN][VICARE_NAME]} Water", vicare_api)] + [ + ViCareWater( + f"{hass.data[VICARE_DOMAIN][VICARE_NAME]} Water", + vicare_api, + heating_type, + ) + ] ) class ViCareWater(WaterHeaterDevice): """Representation of the ViCare domestic hot water device.""" - def __init__(self, name, api): + def __init__(self, name, api, heating_type): """Initialize the DHW water_heater device.""" self._name = name self._state = None self._api = api + self._attributes = {} self._target_temperature = None self._current_temperature = None self._current_mode = None + self._heating_type = heating_type def update(self): """Let HA know there has been an update from the ViCare API.""" diff --git a/requirements_all.txt b/requirements_all.txt index 64cc58eeb23e015e62c4af91e191a2ddb3a500b9..8635b19ae06e5704237843396b4fd3f817f290d9 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -78,7 +78,7 @@ PySocks==1.7.1 PyTransportNSW==0.1.1 # homeassistant.components.vicare -PyViCare==0.1.1 +PyViCare==0.1.2 # homeassistant.components.xiaomi_aqara PyXiaomiGateway==0.12.4