mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Use climate enums in lyric (#70682)
This commit is contained in:
parent
3c097d5672
commit
f2d5433339
@ -9,22 +9,13 @@ from aiolyric.objects.device import LyricDevice
|
||||
from aiolyric.objects.location import LyricLocation
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ClimateEntity,
|
||||
ClimateEntityDescription,
|
||||
ClimateEntityFeature,
|
||||
)
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityDescription
|
||||
from homeassistant.components.climate.const import (
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
ATTR_TARGET_TEMP_LOW,
|
||||
CURRENT_HVAC_COOL,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
CURRENT_HVAC_OFF,
|
||||
HVAC_MODE_COOL,
|
||||
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
|
||||
@ -69,23 +60,23 @@ LYRIC_HVAC_MODE_COOL = "Cool"
|
||||
LYRIC_HVAC_MODE_HEAT_COOL = "Auto"
|
||||
|
||||
LYRIC_HVAC_MODES = {
|
||||
HVAC_MODE_OFF: LYRIC_HVAC_MODE_OFF,
|
||||
HVAC_MODE_HEAT: LYRIC_HVAC_MODE_HEAT,
|
||||
HVAC_MODE_COOL: LYRIC_HVAC_MODE_COOL,
|
||||
HVAC_MODE_HEAT_COOL: LYRIC_HVAC_MODE_HEAT_COOL,
|
||||
HVACMode.OFF: LYRIC_HVAC_MODE_OFF,
|
||||
HVACMode.HEAT: LYRIC_HVAC_MODE_HEAT,
|
||||
HVACMode.COOL: LYRIC_HVAC_MODE_COOL,
|
||||
HVACMode.HEAT_COOL: LYRIC_HVAC_MODE_HEAT_COOL,
|
||||
}
|
||||
|
||||
HVAC_MODES = {
|
||||
LYRIC_HVAC_MODE_OFF: HVAC_MODE_OFF,
|
||||
LYRIC_HVAC_MODE_HEAT: HVAC_MODE_HEAT,
|
||||
LYRIC_HVAC_MODE_COOL: HVAC_MODE_COOL,
|
||||
LYRIC_HVAC_MODE_HEAT_COOL: HVAC_MODE_HEAT_COOL,
|
||||
LYRIC_HVAC_MODE_OFF: HVACMode.OFF,
|
||||
LYRIC_HVAC_MODE_HEAT: HVACMode.HEAT,
|
||||
LYRIC_HVAC_MODE_COOL: HVACMode.COOL,
|
||||
LYRIC_HVAC_MODE_HEAT_COOL: HVACMode.HEAT_COOL,
|
||||
}
|
||||
|
||||
HVAC_ACTIONS = {
|
||||
LYRIC_HVAC_ACTION_OFF: CURRENT_HVAC_OFF,
|
||||
LYRIC_HVAC_ACTION_HEAT: CURRENT_HVAC_HEAT,
|
||||
LYRIC_HVAC_ACTION_COOL: CURRENT_HVAC_COOL,
|
||||
LYRIC_HVAC_ACTION_OFF: HVACAction.OFF,
|
||||
LYRIC_HVAC_ACTION_HEAT: HVACAction.HEATING,
|
||||
LYRIC_HVAC_ACTION_COOL: HVACAction.COOLING,
|
||||
}
|
||||
|
||||
SERVICE_HOLD_TIME = "set_hold_time"
|
||||
@ -152,20 +143,20 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
self._temperature_unit = temperature_unit
|
||||
|
||||
# Setup supported hvac modes
|
||||
self._hvac_modes = [HVAC_MODE_OFF]
|
||||
self._attr_hvac_modes = [HVACMode.OFF]
|
||||
|
||||
# Add supported lyric thermostat features
|
||||
if LYRIC_HVAC_MODE_HEAT in device.allowedModes:
|
||||
self._hvac_modes.append(HVAC_MODE_HEAT)
|
||||
self._attr_hvac_modes.append(HVACMode.HEAT)
|
||||
|
||||
if LYRIC_HVAC_MODE_COOL in device.allowedModes:
|
||||
self._hvac_modes.append(HVAC_MODE_COOL)
|
||||
self._attr_hvac_modes.append(HVACMode.COOL)
|
||||
|
||||
if (
|
||||
LYRIC_HVAC_MODE_HEAT in device.allowedModes
|
||||
and LYRIC_HVAC_MODE_COOL in device.allowedModes
|
||||
):
|
||||
self._hvac_modes.append(HVAC_MODE_HEAT_COOL)
|
||||
self._attr_hvac_modes.append(HVACMode.HEAT_COOL)
|
||||
|
||||
super().__init__(
|
||||
coordinator,
|
||||
@ -195,33 +186,28 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
return self.device.indoorTemperature
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str:
|
||||
def hvac_action(self) -> HVACAction:
|
||||
"""Return the current hvac action."""
|
||||
action = HVAC_ACTIONS.get(self.device.operationStatus.mode, None)
|
||||
if action == CURRENT_HVAC_OFF and self.hvac_mode != HVAC_MODE_OFF:
|
||||
action = CURRENT_HVAC_IDLE
|
||||
if action == HVACAction.OFF and self.hvac_mode != HVACMode.OFF:
|
||||
action = HVACAction.IDLE
|
||||
return action
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""Return the hvac mode."""
|
||||
return HVAC_MODES[self.device.changeableValues.mode]
|
||||
|
||||
@property
|
||||
def hvac_modes(self) -> list[str]:
|
||||
"""List of available hvac modes."""
|
||||
return self._hvac_modes
|
||||
|
||||
@property
|
||||
def target_temperature(self) -> float | None:
|
||||
"""Return the temperature we try to reach."""
|
||||
device = self.device
|
||||
if (
|
||||
device.changeableValues.autoChangeoverActive
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVAC_MODE_OFF
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVACMode.OFF
|
||||
):
|
||||
return None
|
||||
if self.hvac_mode == HVAC_MODE_COOL:
|
||||
if self.hvac_mode == HVACMode.COOL:
|
||||
return device.changeableValues.coolSetpoint
|
||||
return device.changeableValues.heatSetpoint
|
||||
|
||||
@ -231,7 +217,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
device = self.device
|
||||
if (
|
||||
not device.changeableValues.autoChangeoverActive
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVAC_MODE_OFF
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVACMode.OFF
|
||||
):
|
||||
return None
|
||||
return device.changeableValues.coolSetpoint
|
||||
@ -242,7 +228,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
device = self.device
|
||||
if (
|
||||
not device.changeableValues.autoChangeoverActive
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVAC_MODE_OFF
|
||||
or HVAC_MODES[device.changeableValues.mode] == HVACMode.OFF
|
||||
):
|
||||
return None
|
||||
return device.changeableValues.heatSetpoint
|
||||
@ -281,7 +267,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
"""Set new target temperature."""
|
||||
if self.hvac_mode == HVAC_MODE_OFF:
|
||||
if self.hvac_mode == HVACMode.OFF:
|
||||
return
|
||||
|
||||
device = self.device
|
||||
@ -309,7 +295,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
_LOGGER.debug("Set temperature: %s", temp)
|
||||
try:
|
||||
if self.hvac_mode == HVAC_MODE_COOL:
|
||||
if self.hvac_mode == HVACMode.COOL:
|
||||
await self._update_thermostat(
|
||||
self.location, device, coolSetpoint=temp
|
||||
)
|
||||
@ -321,7 +307,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
_LOGGER.error(exception)
|
||||
await self.coordinator.async_refresh()
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set hvac mode."""
|
||||
_LOGGER.debug("HVAC mode: %s", hvac_mode)
|
||||
try:
|
||||
@ -330,7 +316,7 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
||||
# Auto briefly and then reverts to Off (perhaps related to heatCoolMode). This is the
|
||||
# behavior that happens with the native app as well, so likely a bug in the api itself
|
||||
|
||||
if HVAC_MODES[self.device.changeableValues.mode] == HVAC_MODE_OFF:
|
||||
if HVAC_MODES[self.device.changeableValues.mode] == HVACMode.OFF:
|
||||
_LOGGER.debug(
|
||||
"HVAC mode passed to lyric: %s",
|
||||
HVAC_MODES[LYRIC_HVAC_MODE_COOL],
|
||||
|
Loading…
Reference in New Issue
Block a user