Skip to content

Commit

Permalink
fix: Lyric has an actual "Auto" mode that is exposed if the device ha…
Browse files Browse the repository at this point in the history
…s an Auto mode.
  • Loading branch information
kristof-mattei committed Sep 8, 2024
1 parent 8ce236d commit da673d9
Showing 1 changed file with 40 additions and 86 deletions.
126 changes: 40 additions & 86 deletions homeassistant/components/lyric/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@
_LOGGER = logging.getLogger(__name__)

# Only LCC models support presets
SUPPORT_FLAGS_LCC = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
SUPPORT_FLAGS_TCC = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
SUPPORT_FLAGS_LCC = (ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE |
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE)
SUPPORT_FLAGS_TCC = (ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TARGET_TEMPERATURE_RANGE)

LYRIC_HVAC_ACTION_OFF = "EquipmentOff"
LYRIC_HVAC_ACTION_HEAT = "Heat"
Expand Down Expand Up @@ -113,34 +107,29 @@
ATTR_TIME_PERIOD = "time_period"

SCHEMA_HOLD_TIME: VolDictType = {
vol.Required(ATTR_TIME_PERIOD, default="01:00:00"): vol.All(
cv.time_period,
cv.positive_timedelta,
lambda td: strftime("%H:%M:%S", localtime(time() + td.total_seconds())),
)
vol.Required(ATTR_TIME_PERIOD, default="01:00:00"):
vol.All(
cv.time_period,
cv.positive_timedelta,
lambda td: strftime("%H:%M:%S", localtime(time() + td.total_seconds())),
)
}


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback) -> None:
"""Set up the Honeywell Lyric climate platform based on a config entry."""
coordinator: DataUpdateCoordinator[Lyric] = hass.data[DOMAIN][entry.entry_id]

async_add_entities(
(
LyricClimate(
coordinator,
ClimateEntityDescription(
key=f"{device.mac_id}_thermostat",
name=device.name,
),
location,
device,
)
for location in coordinator.data.locations
for device in location.devices
),
(LyricClimate(
coordinator,
ClimateEntityDescription(
key=f"{device.mac_id}_thermostat",
name=device.name,
),
location,
device,
) for location in coordinator.data.locations for device in location.devices),
True,
)

Expand Down Expand Up @@ -208,10 +197,7 @@ def __init__(
if LYRIC_HVAC_MODE_COOL in device.allowed_modes:
self._attr_hvac_modes.append(HVACMode.COOL)

if (
LYRIC_HVAC_MODE_HEAT in device.allowed_modes
and LYRIC_HVAC_MODE_COOL in device.allowed_modes
):
if LYRIC_HVAC_MODE_HEAT_COOL in device.allowedModes:
self._attr_hvac_modes.append(HVACMode.HEAT_COOL)

# Setup supported features
Expand All @@ -221,22 +207,14 @@ def __init__(
self._attr_supported_features = SUPPORT_FLAGS_TCC

# Setup supported fan modes
if device_fan_modes := device.settings.attributes.get("fan", {}).get(
"allowedModes"
):
if device_fan_modes := device.settings.attributes.get("fan", {}).get("allowedModes"):
self._attr_fan_modes = [
FAN_MODES[device_fan_mode]
for device_fan_mode in device_fan_modes
if device_fan_mode in FAN_MODES
FAN_MODES[device_fan_mode] for device_fan_mode in device_fan_modes if device_fan_mode in FAN_MODES
]
self._attr_supported_features = (
self._attr_supported_features | ClimateEntityFeature.FAN_MODE
)
self._attr_supported_features = (self._attr_supported_features | ClimateEntityFeature.FAN_MODE)

if len(self.hvac_modes) > 1:
self._attr_supported_features |= (
ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
)
self._attr_supported_features |= (ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON)

super().__init__(
coordinator,
Expand Down Expand Up @@ -268,10 +246,8 @@ def hvac_mode(self) -> HVACMode:
def target_temperature(self) -> float | None:
"""Return the temperature we try to reach."""
device = self.device
if (
device.changeable_values.auto_changeover_active
or HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF
):
if (device.changeable_values.auto_changeover_active or
HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF):
return None
if self.hvac_mode == HVACMode.COOL:
return device.changeable_values.cool_setpoint
Expand All @@ -281,21 +257,17 @@ def target_temperature(self) -> float | None:
def target_temperature_high(self) -> float | None:
"""Return the highbound target temperature we try to reach."""
device = self.device
if (
not device.changeable_values.auto_changeover_active
or HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF
):
if (not device.changeable_values.auto_changeover_active or
HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF):
return None
return device.changeable_values.cool_setpoint

@property
def target_temperature_low(self) -> float | None:
"""Return the lowbound target temperature we try to reach."""
device = self.device
if (
not device.changeable_values.auto_changeover_active
or HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF
):
if (not device.changeable_values.auto_changeover_active or
HVAC_MODES[device.changeable_values.mode] == HVACMode.OFF):
return None
return device.changeable_values.heat_setpoint

Expand Down Expand Up @@ -324,11 +296,7 @@ def max_temp(self) -> float:
def fan_mode(self) -> str | None:
"""Return current fan mode."""
device = self.device
return FAN_MODES.get(
device.settings.attributes.get("fan", {})
.get("changeableValues", {})
.get("mode")
)
return FAN_MODES.get(device.settings.attributes.get("fan", {}).get("changeableValues", {}).get("mode"))

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
Expand All @@ -341,10 +309,8 @@ async def async_set_temperature(self, **kwargs: Any) -> None:

if device.changeable_values.mode == LYRIC_HVAC_MODE_HEAT_COOL:
if target_temp_low is None or target_temp_high is None:
raise HomeAssistantError(
"Could not find target_temp_low and/or target_temp_high in"
" arguments"
)
raise HomeAssistantError("Could not find target_temp_low and/or target_temp_high in"
" arguments")

# If TCC device pass the heatCoolMode value, otherwise
# if LCC device can skip the mode altogether
Expand All @@ -370,13 +336,9 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
_LOGGER.debug("Set temperature: %s", temp)
try:
if self.hvac_mode == HVACMode.COOL:
await self._update_thermostat(
self.location, device, cool_setpoint=temp
)
await self._update_thermostat(self.location, device, cool_setpoint=temp)
else:
await self._update_thermostat(
self.location, device, heat_setpoint=temp
)
await self._update_thermostat(self.location, device, heat_setpoint=temp)
except LYRIC_EXCEPTIONS as exception:
_LOGGER.error(exception)
await self.coordinator.async_refresh()
Expand Down Expand Up @@ -429,9 +391,7 @@ async def _async_set_hvac_mode_tcc(self, hvac_mode: HVACMode) -> None:
"HVAC mode passed to lyric: %s",
HVAC_MODES[self.device.changeable_values.mode],
)
await self._update_thermostat(
self.location, self.device, auto_changeover_active=True
)
await self._update_thermostat(self.location, self.device, auto_changeover_active=True)
else:
_LOGGER.debug("HVAC mode passed to lyric: %s", LYRIC_HVAC_MODES[hvac_mode])
await self._update_thermostat(
Expand All @@ -446,10 +406,8 @@ 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])
# Set auto_changeover_active to True if the mode being passed is Auto
# otherwise leave unchanged.
if (
LYRIC_HVAC_MODES[hvac_mode] == LYRIC_HVAC_MODE_HEAT_COOL
and not self.device.changeable_values.auto_changeover_active
):
if (LYRIC_HVAC_MODES[hvac_mode] == LYRIC_HVAC_MODE_HEAT_COOL and
not self.device.changeable_values.auto_changeover_active):
auto_changeover = True
else:
auto_changeover = None
Expand All @@ -465,9 +423,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set preset (PermanentHold, HoldUntil, NoHold, VacationHold) mode."""
_LOGGER.debug("Set preset mode: %s", preset_mode)
try:
await self._update_thermostat(
self.location, self.device, thermostat_setpoint_status=preset_mode
)
await self._update_thermostat(self.location, self.device, thermostat_setpoint_status=preset_mode)
except LYRIC_EXCEPTIONS as exception:
_LOGGER.error(exception)
await self.coordinator.async_refresh()
Expand All @@ -491,9 +447,7 @@ async def async_set_fan_mode(self, fan_mode: str) -> None:
_LOGGER.debug("Set fan mode: %s", fan_mode)
try:
_LOGGER.debug("Fan mode passed to lyric: %s", LYRIC_FAN_MODES[fan_mode])
await self._update_fan(
self.location, self.device, mode=LYRIC_FAN_MODES[fan_mode]
)
await self._update_fan(self.location, self.device, mode=LYRIC_FAN_MODES[fan_mode])
except LYRIC_EXCEPTIONS as exception:
_LOGGER.error(exception)
except KeyError:
Expand Down

0 comments on commit da673d9

Please sign in to comment.