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