Use climate enums in mysensors (#70692)
parent
6363c67398
commit
57ae1f930f
|
@ -4,14 +4,12 @@ from __future__ import annotations
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components import mysensors
|
from homeassistant.components import mysensors
|
||||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
HVAC_MODE_AUTO,
|
ClimateEntityFeature,
|
||||||
HVAC_MODE_COOL,
|
HVACMode,
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -28,20 +26,20 @@ from .const import MYSENSORS_DISCOVERY, DiscoveryInfo
|
||||||
from .helpers import on_unload
|
from .helpers import on_unload
|
||||||
|
|
||||||
DICT_HA_TO_MYS = {
|
DICT_HA_TO_MYS = {
|
||||||
HVAC_MODE_AUTO: "AutoChangeOver",
|
HVACMode.AUTO: "AutoChangeOver",
|
||||||
HVAC_MODE_COOL: "CoolOn",
|
HVACMode.COOL: "CoolOn",
|
||||||
HVAC_MODE_HEAT: "HeatOn",
|
HVACMode.HEAT: "HeatOn",
|
||||||
HVAC_MODE_OFF: "Off",
|
HVACMode.OFF: "Off",
|
||||||
}
|
}
|
||||||
DICT_MYS_TO_HA = {
|
DICT_MYS_TO_HA = {
|
||||||
"AutoChangeOver": HVAC_MODE_AUTO,
|
"AutoChangeOver": HVACMode.AUTO,
|
||||||
"CoolOn": HVAC_MODE_COOL,
|
"CoolOn": HVACMode.COOL,
|
||||||
"HeatOn": HVAC_MODE_HEAT,
|
"HeatOn": HVACMode.HEAT,
|
||||||
"Off": HVAC_MODE_OFF,
|
"Off": HVACMode.OFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
FAN_LIST = ["Auto", "Min", "Normal", "Max"]
|
FAN_LIST = ["Auto", "Min", "Normal", "Max"]
|
||||||
OPERATION_LIST = [HVAC_MODE_OFF, HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_HEAT]
|
OPERATION_LIST = [HVACMode.OFF, HVACMode.AUTO, HVACMode.COOL, HVACMode.HEAT]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -75,6 +73,8 @@ async def async_setup_entry(
|
||||||
class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
|
class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
|
||||||
"""Representation of a MySensors HVAC."""
|
"""Representation of a MySensors HVAC."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = OPERATION_LIST
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
|
@ -142,14 +142,9 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return current operation ie. heat, cool, idle."""
|
"""Return current operation ie. heat, cool, idle."""
|
||||||
return self._values.get(self.value_type, HVAC_MODE_HEAT)
|
return self._values.get(self.value_type, HVACMode.HEAT)
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self) -> list[str]:
|
|
||||||
"""List of available operation modes."""
|
|
||||||
return OPERATION_LIST
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self) -> str | None:
|
def fan_mode(self) -> str | None:
|
||||||
|
@ -204,7 +199,7 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
|
||||||
self._values[set_req.V_HVAC_SPEED] = fan_mode
|
self._values[set_req.V_HVAC_SPEED] = fan_mode
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
self.gateway.set_child_value(
|
self.gateway.set_child_value(
|
||||||
self.node_id,
|
self.node_id,
|
||||||
|
|
Loading…
Reference in New Issue