Use climate enums in insteon (#70673)
parent
073833fcec
commit
7cbe56dcdf
|
@ -4,21 +4,16 @@ from __future__ import annotations
|
|||
from pyinsteon.constants import ThermostatMode
|
||||
from pyinsteon.operating_flag import CELSIUS
|
||||
|
||||
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,
|
||||
CURRENT_HVAC_COOL,
|
||||
CURRENT_HVAC_FAN,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
DOMAIN as CLIMATE_DOMAIN,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_FAN_ONLY,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_HEAT_COOL,
|
||||
HVAC_MODE_OFF,
|
||||
ClimateEntityFeature,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
|
@ -46,10 +41,10 @@ HUMIDITY_LOW = 17
|
|||
|
||||
|
||||
HVAC_MODES = {
|
||||
0: HVAC_MODE_OFF,
|
||||
1: HVAC_MODE_HEAT,
|
||||
2: HVAC_MODE_COOL,
|
||||
3: HVAC_MODE_HEAT_COOL,
|
||||
0: HVACMode.OFF,
|
||||
1: HVACMode.HEAT,
|
||||
2: HVACMode.COOL,
|
||||
3: HVACMode.HEAT_COOL,
|
||||
}
|
||||
FAN_MODES = {4: HVAC_MODE_AUTO, 8: HVAC_MODE_FAN_ONLY}
|
||||
|
||||
|
@ -100,12 +95,12 @@ class InsteonClimateEntity(InsteonEntity, ClimateEntity):
|
|||
return self._insteon_device.groups[HUMIDITY].value
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""Return hvac operation ie. heat, cool mode."""
|
||||
return HVAC_MODES[self._insteon_device.groups[SYSTEM_MODE].value]
|
||||
|
||||
@property
|
||||
def hvac_modes(self) -> list[str]:
|
||||
def hvac_modes(self) -> list[HVACMode]:
|
||||
"""Return the list of available hvac operation modes."""
|
||||
return list(HVAC_MODES.values())
|
||||
|
||||
|
@ -161,18 +156,18 @@ class InsteonClimateEntity(InsteonEntity, ClimateEntity):
|
|||
return 1
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str | None:
|
||||
def hvac_action(self) -> HVACAction:
|
||||
"""Return the current running hvac operation if supported.
|
||||
|
||||
Need to be one of CURRENT_HVAC_*.
|
||||
"""
|
||||
if self._insteon_device.groups[COOLING].value:
|
||||
return CURRENT_HVAC_COOL
|
||||
return HVACAction.COOLING
|
||||
if self._insteon_device.groups[HEATING].value:
|
||||
return CURRENT_HVAC_HEAT
|
||||
return HVACAction.HEATING
|
||||
if self._insteon_device.groups[FAN_MODE].value == ThermostatMode.FAN_ALWAYS_ON:
|
||||
return CURRENT_HVAC_FAN
|
||||
return CURRENT_HVAC_IDLE
|
||||
return HVACAction.FAN
|
||||
return HVACAction.IDLE
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
@ -205,7 +200,7 @@ class InsteonClimateEntity(InsteonEntity, ClimateEntity):
|
|||
mode = list(FAN_MODES)[list(FAN_MODES.values()).index(fan_mode)]
|
||||
await self._insteon_device.async_set_mode(mode)
|
||||
|
||||
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 hvac mode."""
|
||||
mode = list(HVAC_MODES)[list(HVAC_MODES.values()).index(hvac_mode)]
|
||||
await self._insteon_device.async_set_mode(mode)
|
||||
|
|
Loading…
Reference in New Issue