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
This commit is contained in:
Maikel Punie 2021-10-26 10:53:13 +02:00 committed by GitHub
parent d0cc2a530a
commit 00377a926e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 29 deletions

View File

@ -1,13 +1,16 @@
"""Support for Velbus thermostat.""" """Support for Velbus thermostat."""
from __future__ import annotations
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from . import VelbusEntity from . import VelbusEntity
from .const import DOMAIN from .const import DOMAIN, PRESET_MODES
async def async_setup_entry(hass, entry, async_add_entities): async def async_setup_entry(hass, entry, async_add_entities):
@ -24,47 +27,60 @@ class VelbusClimate(VelbusEntity, ClimateEntity):
"""Representation of a Velbus thermostat.""" """Representation of a Velbus thermostat."""
@property @property
def supported_features(self): def supported_features(self) -> int:
"""Return the list off supported features.""" """Return the list off supported features."""
return SUPPORT_TARGET_TEMPERATURE return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
@property @property
def temperature_unit(self): def temperature_unit(self) -> str:
"""Return the unit.""" """Return the unit."""
return TEMP_CELSIUS return TEMP_CELSIUS
@property @property
def current_temperature(self): def current_temperature(self) -> int | None:
"""Return the current temperature.""" """Return the current temperature."""
return self._channel.get_state() return self._channel.get_state()
@property @property
def hvac_mode(self): def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode. """Return hvac operation ie. heat, cool mode."""
Need to be one of HVAC_MODE_*.
"""
return HVAC_MODE_HEAT return HVAC_MODE_HEAT
@property @property
def hvac_modes(self): def hvac_modes(self) -> list[str]:
"""Return the list of available hvac operation modes. """Return the list of available hvac operation modes."""
Need to be a subset of HVAC_MODES.
"""
return [HVAC_MODE_HEAT] return [HVAC_MODE_HEAT]
@property @property
def target_temperature(self): def target_temperature(self) -> int | None:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
return self._channel.get_climate_target() 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.""" """Set new target temperatures."""
if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: if (temp := kwargs.get(ATTR_TEMPERATURE)) is None:
return return
self._channel.set_temp(temp) await self._channel.set_temp(temp)
self.schedule_update_ha_state() self.schedule_update_ha_state()
def set_hvac_mode(self, hvac_mode): async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new target hvac mode.""" """Set the new preset mode."""
await self._channel.set_preset(PRESET_MODES[preset_mode])
self.async_write_ha_state()

View File

@ -1,10 +1,25 @@
"""Const for Velbus.""" """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" DOMAIN: Final = "velbus"
CONF_MEMO_TEXT = "memo_text"
SERVICE_SCAN = "scan" CONF_INTERFACE: Final = "interface"
SERVICE_SYNC = "sync_clock" CONF_MEMO_TEXT: Final = "memo_text"
SERVICE_SET_MEMO_TEXT = "set_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",
}

View File

@ -2,7 +2,7 @@
"domain": "velbus", "domain": "velbus",
"name": "Velbus", "name": "Velbus",
"documentation": "https://www.home-assistant.io/integrations/velbus", "documentation": "https://www.home-assistant.io/integrations/velbus",
"requirements": ["velbus-aio==2021.10.6"], "requirements": ["velbus-aio==2021.10.7"],
"config_flow": true, "config_flow": true,
"codeowners": ["@Cereal2nd", "@brefra"], "codeowners": ["@Cereal2nd", "@brefra"],
"iot_class": "local_push" "iot_class": "local_push"

View File

@ -2360,7 +2360,7 @@ uvcclient==0.11.0
vallox-websocket-api==2.8.1 vallox-websocket-api==2.8.1
# homeassistant.components.velbus # homeassistant.components.velbus
velbus-aio==2021.10.6 velbus-aio==2021.10.7
# homeassistant.components.venstar # homeassistant.components.venstar
venstarcolortouch==0.14 venstarcolortouch==0.14

View File

@ -1364,7 +1364,7 @@ url-normalize==1.4.1
uvcclient==0.11.0 uvcclient==0.11.0
# homeassistant.components.velbus # homeassistant.components.velbus
velbus-aio==2021.10.6 velbus-aio==2021.10.7
# homeassistant.components.venstar # homeassistant.components.venstar
venstarcolortouch==0.14 venstarcolortouch==0.14