From 00377a926e0d4dae6df000937f4c5f5887a7bd1e Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Tue, 26 Oct 2021 10:53:13 +0200 Subject: [PATCH] Fix velbus climate (#58408) * Initial work on velbus climate fixes home-assistant/core#58382 * Clean up the code, fixed the preset_mode * Fix climate havc mode return value --- homeassistant/components/velbus/climate.py | 56 ++++++++++++------- homeassistant/components/velbus/const.py | 27 +++++++-- homeassistant/components/velbus/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 60 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/velbus/climate.py b/homeassistant/components/velbus/climate.py index 318dff463f0..5c18243e371 100644 --- a/homeassistant/components/velbus/climate.py +++ b/homeassistant/components/velbus/climate.py @@ -1,13 +1,16 @@ """Support for Velbus thermostat.""" +from __future__ import annotations + from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( HVAC_MODE_HEAT, + SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from . import VelbusEntity -from .const import DOMAIN +from .const import DOMAIN, PRESET_MODES async def async_setup_entry(hass, entry, async_add_entities): @@ -24,47 +27,60 @@ class VelbusClimate(VelbusEntity, ClimateEntity): """Representation of a Velbus thermostat.""" @property - def supported_features(self): + def supported_features(self) -> int: """Return the list off supported features.""" - return SUPPORT_TARGET_TEMPERATURE + return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE @property - def temperature_unit(self): + def temperature_unit(self) -> str: """Return the unit.""" return TEMP_CELSIUS @property - def current_temperature(self): + def current_temperature(self) -> int | None: """Return the current temperature.""" return self._channel.get_state() @property - def hvac_mode(self): - """Return hvac operation ie. heat, cool mode. - - Need to be one of HVAC_MODE_*. - """ + def hvac_mode(self) -> str: + """Return hvac operation ie. heat, cool mode.""" return HVAC_MODE_HEAT @property - def hvac_modes(self): - """Return the list of available hvac operation modes. - - Need to be a subset of HVAC_MODES. - """ + def hvac_modes(self) -> list[str]: + """Return the list of available hvac operation modes.""" return [HVAC_MODE_HEAT] @property - def target_temperature(self): + def target_temperature(self) -> int | None: """Return the temperature we try to reach.""" return self._channel.get_climate_target() - def set_temperature(self, **kwargs): + @property + def preset_modes(self) -> list[str] | None: + """Return a list of all possible presets.""" + return list(PRESET_MODES.keys()) + + @property + def preset_mode(self) -> str | None: + """Return the current Preset for this channel.""" + return next( + ( + key + for key, val in PRESET_MODES.items() + if val == self._channel.get_climate_preset() + ), + None, + ) + + async def async_set_temperature(self, **kwargs) -> None: """Set new target temperatures.""" if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: return - self._channel.set_temp(temp) + await self._channel.set_temp(temp) self.schedule_update_ha_state() - def set_hvac_mode(self, hvac_mode): - """Set new target hvac mode.""" + async def async_set_preset_mode(self, preset_mode: str) -> None: + """Set the new preset mode.""" + await self._channel.set_preset(PRESET_MODES[preset_mode]) + self.async_write_ha_state() diff --git a/homeassistant/components/velbus/const.py b/homeassistant/components/velbus/const.py index 69c0c926136..d295c725d21 100644 --- a/homeassistant/components/velbus/const.py +++ b/homeassistant/components/velbus/const.py @@ -1,10 +1,25 @@ """Const for Velbus.""" +from typing import Final -DOMAIN = "velbus" +from homeassistant.components.climate.const import ( + PRESET_AWAY, + PRESET_COMFORT, + PRESET_ECO, + PRESET_HOME, +) -CONF_INTERFACE = "interface" -CONF_MEMO_TEXT = "memo_text" +DOMAIN: Final = "velbus" -SERVICE_SCAN = "scan" -SERVICE_SYNC = "sync_clock" -SERVICE_SET_MEMO_TEXT = "set_memo_text" +CONF_INTERFACE: Final = "interface" +CONF_MEMO_TEXT: Final = "memo_text" + +SERVICE_SCAN: Final = "scan" +SERVICE_SYNC: Final = "sync_clock" +SERVICE_SET_MEMO_TEXT: Final = "set_memo_text" + +PRESET_MODES: Final = { + PRESET_ECO: "safe", + PRESET_AWAY: "night", + PRESET_HOME: "day", + PRESET_COMFORT: "comfort", +} diff --git a/homeassistant/components/velbus/manifest.json b/homeassistant/components/velbus/manifest.json index 8c84c3944f8..4541b428a4a 100644 --- a/homeassistant/components/velbus/manifest.json +++ b/homeassistant/components/velbus/manifest.json @@ -2,7 +2,7 @@ "domain": "velbus", "name": "Velbus", "documentation": "https://www.home-assistant.io/integrations/velbus", - "requirements": ["velbus-aio==2021.10.6"], + "requirements": ["velbus-aio==2021.10.7"], "config_flow": true, "codeowners": ["@Cereal2nd", "@brefra"], "iot_class": "local_push" diff --git a/requirements_all.txt b/requirements_all.txt index 6ee4e154dde..54555279d2f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2360,7 +2360,7 @@ uvcclient==0.11.0 vallox-websocket-api==2.8.1 # homeassistant.components.velbus -velbus-aio==2021.10.6 +velbus-aio==2021.10.7 # homeassistant.components.venstar venstarcolortouch==0.14 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d153bef0caa..215ed38842d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1364,7 +1364,7 @@ url-normalize==1.4.1 uvcclient==0.11.0 # homeassistant.components.velbus -velbus-aio==2021.10.6 +velbus-aio==2021.10.7 # homeassistant.components.venstar venstarcolortouch==0.14