Improve fans in homekit_controller (#74440)

This commit is contained in:
J. Nick Koston
2022-07-05 09:25:30 -05:00
committed by GitHub
parent 809f101f55
commit f6cb2833ca
9 changed files with 205 additions and 198 deletions

View File

@@ -25,6 +25,8 @@ from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
FAN_AUTO,
FAN_ON,
SWING_OFF,
SWING_VERTICAL,
ClimateEntityFeature,
@@ -72,6 +74,7 @@ TARGET_HEATER_COOLER_STATE_HOMEKIT_TO_HASS = {
TargetHeaterCoolerStateValues.COOL: HVACMode.COOL,
}
# Map of hass operation modes to homekit modes
MODE_HASS_TO_HOMEKIT = {v: k for k, v in MODE_HOMEKIT_TO_HASS.items()}
@@ -104,19 +107,65 @@ async def async_setup_entry(
conn.add_listener(async_add_service)
class HomeKitHeaterCoolerEntity(HomeKitEntity, ClimateEntity):
"""Representation of a Homekit climate device."""
class HomeKitBaseClimateEntity(HomeKitEntity, ClimateEntity):
"""The base HomeKit Controller climate entity."""
_attr_temperature_unit = TEMP_CELSIUS
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return [
CharacteristicsTypes.TEMPERATURE_CURRENT,
CharacteristicsTypes.FAN_STATE_TARGET,
]
@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
return self.service.value(CharacteristicsTypes.TEMPERATURE_CURRENT)
@property
def fan_modes(self) -> list[str] | None:
"""Return the available fan modes."""
if self.service.has(CharacteristicsTypes.FAN_STATE_TARGET):
return [FAN_ON, FAN_AUTO]
return None
@property
def fan_mode(self) -> str | None:
"""Return the current fan mode."""
fan_mode = self.service.value(CharacteristicsTypes.FAN_STATE_TARGET)
return FAN_AUTO if fan_mode else FAN_ON
async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Turn fan to manual/auto."""
await self.async_put_characteristics(
{CharacteristicsTypes.FAN_STATE_TARGET: int(fan_mode == FAN_AUTO)}
)
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
features = 0
if self.service.has(CharacteristicsTypes.FAN_STATE_TARGET):
features |= ClimateEntityFeature.FAN_MODE
return features
class HomeKitHeaterCoolerEntity(HomeKitBaseClimateEntity):
"""Representation of a Homekit climate device."""
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return super().get_characteristic_types() + [
CharacteristicsTypes.ACTIVE,
CharacteristicsTypes.CURRENT_HEATER_COOLER_STATE,
CharacteristicsTypes.TARGET_HEATER_COOLER_STATE,
CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD,
CharacteristicsTypes.TEMPERATURE_HEATING_THRESHOLD,
CharacteristicsTypes.SWING_MODE,
CharacteristicsTypes.TEMPERATURE_CURRENT,
]
async def async_set_temperature(self, **kwargs: Any) -> None:
@@ -162,11 +211,6 @@ class HomeKitHeaterCoolerEntity(HomeKitEntity, ClimateEntity):
}
)
@property
def current_temperature(self) -> float:
"""Return the current temperature."""
return self.service.value(CharacteristicsTypes.TEMPERATURE_CURRENT)
@property
def target_temperature(self) -> float | None:
"""Return the temperature we try to reach."""
@@ -321,7 +365,7 @@ class HomeKitHeaterCoolerEntity(HomeKitEntity, ClimateEntity):
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
features = 0
features = super().supported_features
if self.service.has(CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD):
features |= ClimateEntityFeature.TARGET_TEMPERATURE
@@ -334,22 +378,16 @@ class HomeKitHeaterCoolerEntity(HomeKitEntity, ClimateEntity):
return features
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
class HomeKitClimateEntity(HomeKitBaseClimateEntity):
"""Representation of a Homekit climate device."""
def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return [
return super().get_characteristic_types() + [
CharacteristicsTypes.HEATING_COOLING_CURRENT,
CharacteristicsTypes.HEATING_COOLING_TARGET,
CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD,
CharacteristicsTypes.TEMPERATURE_CURRENT,
CharacteristicsTypes.TEMPERATURE_HEATING_THRESHOLD,
CharacteristicsTypes.TEMPERATURE_TARGET,
CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT,
@@ -411,11 +449,6 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
}
)
@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
return self.service.value(CharacteristicsTypes.TEMPERATURE_CURRENT)
@property
def target_temperature(self) -> float | None:
"""Return the temperature we try to reach."""
@@ -558,7 +591,7 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
@property
def supported_features(self) -> int:
"""Return the list of supported features."""
features = 0
features = super().supported_features
if self.service.has(CharacteristicsTypes.TEMPERATURE_TARGET):
features |= ClimateEntityFeature.TARGET_TEMPERATURE
@@ -573,11 +606,6 @@ class HomeKitClimateEntity(HomeKitEntity, ClimateEntity):
return features
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
ENTITY_TYPES = {
ServicesTypes.HEATER_COOLER: HomeKitHeaterCoolerEntity,