mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add fan modes in Lyric integration (#100420)
* Add fan modes in Lyric integration * add fan_mode only when available * move supported_features to init * mapped fan_modes to built-in modes * log KeyError for fan_modes
This commit is contained in:
parent
f715f5c76f
commit
81af45347f
@ -133,6 +133,7 @@ class LyricEntity(CoordinatorEntity[DataUpdateCoordinator[Lyric]]):
|
|||||||
self._location = location
|
self._location = location
|
||||||
self._mac_id = device.macID
|
self._mac_id = device.macID
|
||||||
self._update_thermostat = coordinator.data.update_thermostat
|
self._update_thermostat = coordinator.data.update_thermostat
|
||||||
|
self._update_fan = coordinator.data.update_fan
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
|
@ -14,6 +14,9 @@ import voluptuous as vol
|
|||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
|
FAN_AUTO,
|
||||||
|
FAN_DIFFUSE,
|
||||||
|
FAN_ON,
|
||||||
ClimateEntity,
|
ClimateEntity,
|
||||||
ClimateEntityDescription,
|
ClimateEntityDescription,
|
||||||
ClimateEntityFeature,
|
ClimateEntityFeature,
|
||||||
@ -67,6 +70,10 @@ LYRIC_HVAC_MODE_HEAT = "Heat"
|
|||||||
LYRIC_HVAC_MODE_COOL = "Cool"
|
LYRIC_HVAC_MODE_COOL = "Cool"
|
||||||
LYRIC_HVAC_MODE_HEAT_COOL = "Auto"
|
LYRIC_HVAC_MODE_HEAT_COOL = "Auto"
|
||||||
|
|
||||||
|
LYRIC_FAN_MODE_ON = "On"
|
||||||
|
LYRIC_FAN_MODE_AUTO = "Auto"
|
||||||
|
LYRIC_FAN_MODE_DIFFUSE = "Circulate"
|
||||||
|
|
||||||
LYRIC_HVAC_MODES = {
|
LYRIC_HVAC_MODES = {
|
||||||
HVACMode.OFF: LYRIC_HVAC_MODE_OFF,
|
HVACMode.OFF: LYRIC_HVAC_MODE_OFF,
|
||||||
HVACMode.HEAT: LYRIC_HVAC_MODE_HEAT,
|
HVACMode.HEAT: LYRIC_HVAC_MODE_HEAT,
|
||||||
@ -81,6 +88,18 @@ HVAC_MODES = {
|
|||||||
LYRIC_HVAC_MODE_HEAT_COOL: HVACMode.HEAT_COOL,
|
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 = {
|
HVAC_ACTIONS = {
|
||||||
LYRIC_HVAC_ACTION_OFF: HVACAction.OFF,
|
LYRIC_HVAC_ACTION_OFF: HVACAction.OFF,
|
||||||
LYRIC_HVAC_ACTION_HEAT: HVACAction.HEATING,
|
LYRIC_HVAC_ACTION_HEAT: HVACAction.HEATING,
|
||||||
@ -179,6 +198,25 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
):
|
):
|
||||||
self._attr_hvac_modes.append(HVACMode.HEAT_COOL)
|
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__(
|
super().__init__(
|
||||||
coordinator,
|
coordinator,
|
||||||
location,
|
location,
|
||||||
@ -187,13 +225,6 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
)
|
)
|
||||||
self.entity_description = description
|
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
|
@property
|
||||||
def current_temperature(self) -> float | None:
|
def current_temperature(self) -> float | None:
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
@ -268,6 +299,16 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
return device.maxHeatSetpoint
|
return device.maxHeatSetpoint
|
||||||
return device.maxCoolSetpoint
|
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:
|
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
if self.hvac_mode == HVACMode.OFF:
|
if self.hvac_mode == HVACMode.OFF:
|
||||||
@ -390,3 +431,20 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||||||
except LYRIC_EXCEPTIONS as exception:
|
except LYRIC_EXCEPTIONS as exception:
|
||||||
_LOGGER.error(exception)
|
_LOGGER.error(exception)
|
||||||
await self.coordinator.async_refresh()
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user