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 valuepull/58375/head
parent
d0cc2a530a
commit
00377a926e
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue