diff --git a/homeassistant/components/lyric/__init__.py b/homeassistant/components/lyric/__init__.py index 3e83fedb72a..d048b31d0b0 100644 --- a/homeassistant/components/lyric/__init__.py +++ b/homeassistant/components/lyric/__init__.py @@ -133,6 +133,7 @@ class LyricEntity(CoordinatorEntity[DataUpdateCoordinator[Lyric]]): self._location = location self._mac_id = device.macID self._update_thermostat = coordinator.data.update_thermostat + self._update_fan = coordinator.data.update_fan @property def unique_id(self) -> str: diff --git a/homeassistant/components/lyric/climate.py b/homeassistant/components/lyric/climate.py index 1522f167a4a..d0bad55ff14 100644 --- a/homeassistant/components/lyric/climate.py +++ b/homeassistant/components/lyric/climate.py @@ -14,6 +14,9 @@ import voluptuous as vol from homeassistant.components.climate import ( ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, + FAN_AUTO, + FAN_DIFFUSE, + FAN_ON, ClimateEntity, ClimateEntityDescription, ClimateEntityFeature, @@ -67,6 +70,10 @@ LYRIC_HVAC_MODE_HEAT = "Heat" LYRIC_HVAC_MODE_COOL = "Cool" LYRIC_HVAC_MODE_HEAT_COOL = "Auto" +LYRIC_FAN_MODE_ON = "On" +LYRIC_FAN_MODE_AUTO = "Auto" +LYRIC_FAN_MODE_DIFFUSE = "Circulate" + LYRIC_HVAC_MODES = { HVACMode.OFF: LYRIC_HVAC_MODE_OFF, HVACMode.HEAT: LYRIC_HVAC_MODE_HEAT, @@ -81,6 +88,18 @@ HVAC_MODES = { LYRIC_HVAC_MODE_HEAT_COOL: HVACMode.HEAT_COOL, } +LYRIC_FAN_MODES = { + FAN_ON: LYRIC_FAN_MODE_ON, + FAN_AUTO: LYRIC_FAN_MODE_AUTO, + FAN_DIFFUSE: LYRIC_FAN_MODE_DIFFUSE, +} + +FAN_MODES = { + LYRIC_FAN_MODE_ON: FAN_ON, + LYRIC_FAN_MODE_AUTO: FAN_AUTO, + LYRIC_FAN_MODE_DIFFUSE: FAN_DIFFUSE, +} + HVAC_ACTIONS = { LYRIC_HVAC_ACTION_OFF: HVACAction.OFF, LYRIC_HVAC_ACTION_HEAT: HVACAction.HEATING, @@ -179,6 +198,25 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity): ): self._attr_hvac_modes.append(HVACMode.HEAT_COOL) + # Setup supported features + if device.changeableValues.thermostatSetpointStatus: + self._attr_supported_features = SUPPORT_FLAGS_LCC + else: + self._attr_supported_features = SUPPORT_FLAGS_TCC + + # Setup supported fan modes + 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 + ] + self._attr_supported_features = ( + self._attr_supported_features | ClimateEntityFeature.FAN_MODE + ) + super().__init__( coordinator, location, @@ -187,13 +225,6 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity): ) self.entity_description = description - @property - def supported_features(self) -> ClimateEntityFeature: - """Return the list of supported features.""" - if self.device.changeableValues.thermostatSetpointStatus: - return SUPPORT_FLAGS_LCC - return SUPPORT_FLAGS_TCC - @property def current_temperature(self) -> float | None: """Return the current temperature.""" @@ -268,6 +299,16 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity): return device.maxHeatSetpoint return device.maxCoolSetpoint + @property + 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") + ) + async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" if self.hvac_mode == HVACMode.OFF: @@ -390,3 +431,20 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity): except LYRIC_EXCEPTIONS as exception: _LOGGER.error(exception) await self.coordinator.async_refresh() + + async def async_set_fan_mode(self, fan_mode: str) -> None: + """Set fan mode.""" + _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] + ) + except LYRIC_EXCEPTIONS as exception: + _LOGGER.error(exception) + except KeyError: + _LOGGER.error( + "The fan mode requested does not have a corresponding mode in lyric: %s", + fan_mode, + ) + await self.coordinator.async_refresh()