1
mirror of https://github.com/home-assistant/core synced 2024-09-12 15:16:21 +02:00

Fix Lyric LCC thermostats auto mode (#104853)

This commit is contained in:
Alex Thompson 2023-12-11 10:27:02 -05:00 committed by GitHub
parent 3963f59121
commit 4c0fda9ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import enum
import logging import logging
from time import localtime, strftime, time from time import localtime, strftime, time
from typing import Any from typing import Any
@ -151,6 +152,13 @@ async def async_setup_entry(
) )
class LyricThermostatType(enum.Enum):
"""Lyric thermostats are classified as TCC or LCC devices."""
TCC = enum.auto()
LCC = enum.auto()
class LyricClimate(LyricDeviceEntity, ClimateEntity): class LyricClimate(LyricDeviceEntity, ClimateEntity):
"""Defines a Honeywell Lyric climate entity.""" """Defines a Honeywell Lyric climate entity."""
@ -201,8 +209,10 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
# Setup supported features # Setup supported features
if device.changeableValues.thermostatSetpointStatus: if device.changeableValues.thermostatSetpointStatus:
self._attr_supported_features = SUPPORT_FLAGS_LCC self._attr_supported_features = SUPPORT_FLAGS_LCC
self._attr_thermostat_type = LyricThermostatType.LCC
else: else:
self._attr_supported_features = SUPPORT_FLAGS_TCC self._attr_supported_features = SUPPORT_FLAGS_TCC
self._attr_thermostat_type = LyricThermostatType.TCC
# Setup supported fan modes # Setup supported fan modes
if device_fan_modes := device.settings.attributes.get("fan", {}).get( if device_fan_modes := device.settings.attributes.get("fan", {}).get(
@ -365,56 +375,69 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
"""Set hvac mode.""" """Set hvac mode."""
_LOGGER.debug("HVAC mode: %s", hvac_mode) _LOGGER.debug("HVAC mode: %s", hvac_mode)
try: try:
if LYRIC_HVAC_MODES[hvac_mode] == LYRIC_HVAC_MODE_HEAT_COOL: match self._attr_thermostat_type:
# If the system is off, turn it to Heat first then to Auto, case LyricThermostatType.TCC:
# otherwise it turns to. await self._async_set_hvac_mode_tcc(hvac_mode)
# Auto briefly and then reverts to Off (perhaps related to case LyricThermostatType.LCC:
# heatCoolMode). This is the behavior that happens with the await self._async_set_hvac_mode_lcc(hvac_mode)
# native app as well, so likely a bug in the api itself except LYRIC_EXCEPTIONS as exception:
if HVAC_MODES[self.device.changeableValues.mode] == HVACMode.OFF: _LOGGER.error(exception)
_LOGGER.debug( await self.coordinator.async_refresh()
"HVAC mode passed to lyric: %s",
HVAC_MODES[LYRIC_HVAC_MODE_COOL], async def _async_set_hvac_mode_tcc(self, hvac_mode: HVACMode) -> None:
) if LYRIC_HVAC_MODES[hvac_mode] == LYRIC_HVAC_MODE_HEAT_COOL:
await self._update_thermostat( # If the system is off, turn it to Heat first then to Auto,
self.location, # otherwise it turns to.
self.device, # Auto briefly and then reverts to Off (perhaps related to
mode=HVAC_MODES[LYRIC_HVAC_MODE_HEAT], # heatCoolMode). This is the behavior that happens with the
autoChangeoverActive=False, # native app as well, so likely a bug in the api itself
) if HVAC_MODES[self.device.changeableValues.mode] == HVACMode.OFF:
# Sleep 3 seconds before proceeding
await asyncio.sleep(3)
_LOGGER.debug(
"HVAC mode passed to lyric: %s",
HVAC_MODES[LYRIC_HVAC_MODE_HEAT],
)
await self._update_thermostat(
self.location,
self.device,
mode=HVAC_MODES[LYRIC_HVAC_MODE_HEAT],
autoChangeoverActive=True,
)
else:
_LOGGER.debug(
"HVAC mode passed to lyric: %s",
HVAC_MODES[self.device.changeableValues.mode],
)
await self._update_thermostat(
self.location, self.device, autoChangeoverActive=True
)
else:
_LOGGER.debug( _LOGGER.debug(
"HVAC mode passed to lyric: %s", LYRIC_HVAC_MODES[hvac_mode] "HVAC mode passed to lyric: %s",
HVAC_MODES[LYRIC_HVAC_MODE_COOL],
) )
await self._update_thermostat( await self._update_thermostat(
self.location, self.location,
self.device, self.device,
mode=LYRIC_HVAC_MODES[hvac_mode], mode=HVAC_MODES[LYRIC_HVAC_MODE_HEAT],
autoChangeoverActive=False, autoChangeoverActive=False,
) )
except LYRIC_EXCEPTIONS as exception: # Sleep 3 seconds before proceeding
_LOGGER.error(exception) await asyncio.sleep(3)
await self.coordinator.async_refresh() _LOGGER.debug(
"HVAC mode passed to lyric: %s",
HVAC_MODES[LYRIC_HVAC_MODE_HEAT],
)
await self._update_thermostat(
self.location,
self.device,
mode=HVAC_MODES[LYRIC_HVAC_MODE_HEAT],
autoChangeoverActive=True,
)
else:
_LOGGER.debug(
"HVAC mode passed to lyric: %s",
HVAC_MODES[self.device.changeableValues.mode],
)
await self._update_thermostat(
self.location, self.device, autoChangeoverActive=True
)
else:
_LOGGER.debug("HVAC mode passed to lyric: %s", LYRIC_HVAC_MODES[hvac_mode])
await self._update_thermostat(
self.location,
self.device,
mode=LYRIC_HVAC_MODES[hvac_mode],
autoChangeoverActive=False,
)
async def _async_set_hvac_mode_lcc(self, hvac_mode: HVACMode) -> None:
_LOGGER.debug("HVAC mode passed to lyric: %s", LYRIC_HVAC_MODES[hvac_mode])
await self._update_thermostat(
self.location,
self.device,
mode=LYRIC_HVAC_MODES[hvac_mode],
)
async def async_set_preset_mode(self, preset_mode: str) -> None: async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set preset (PermanentHold, HoldUntil, NoHold, VacationHold) mode.""" """Set preset (PermanentHold, HoldUntil, NoHold, VacationHold) mode."""