Refactor Advantage Air classes for expansion (#75422)

This commit is contained in:
Brett Adams 2022-07-25 20:20:15 +10:00 committed by GitHub
parent f31f2cca07
commit fc9a0ba46b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 62 deletions

View File

@ -11,7 +11,7 @@ from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from .entity import AdvantageAirEntity from .entity import AdvantageAirAcEntity, AdvantageAirZoneEntity
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
@ -38,7 +38,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AdvantageAirFilter(AdvantageAirEntity, BinarySensorEntity): class AdvantageAirFilter(AdvantageAirAcEntity, BinarySensorEntity):
"""Advantage Air Filter sensor.""" """Advantage Air Filter sensor."""
_attr_device_class = BinarySensorDeviceClass.PROBLEM _attr_device_class = BinarySensorDeviceClass.PROBLEM
@ -48,9 +48,7 @@ class AdvantageAirFilter(AdvantageAirEntity, BinarySensorEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an Advantage Air Filter sensor.""" """Initialize an Advantage Air Filter sensor."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_unique_id = ( self._attr_unique_id += "-filter"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-filter'
)
@property @property
def is_on(self): def is_on(self):
@ -58,7 +56,7 @@ class AdvantageAirFilter(AdvantageAirEntity, BinarySensorEntity):
return self._ac["filterCleanStatus"] return self._ac["filterCleanStatus"]
class AdvantageAirZoneMotion(AdvantageAirEntity, BinarySensorEntity): class AdvantageAirZoneMotion(AdvantageAirZoneEntity, BinarySensorEntity):
"""Advantage Air Zone Motion sensor.""" """Advantage Air Zone Motion sensor."""
_attr_device_class = BinarySensorDeviceClass.MOTION _attr_device_class = BinarySensorDeviceClass.MOTION
@ -67,9 +65,7 @@ class AdvantageAirZoneMotion(AdvantageAirEntity, BinarySensorEntity):
"""Initialize an Advantage Air Zone Motion sensor.""" """Initialize an Advantage Air Zone Motion sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} motion' self._attr_name = f'{self._zone["name"]} motion'
self._attr_unique_id = ( self._attr_unique_id += "-motion"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-motion'
)
@property @property
def is_on(self): def is_on(self):
@ -77,7 +73,7 @@ class AdvantageAirZoneMotion(AdvantageAirEntity, BinarySensorEntity):
return self._zone["motion"] == 20 return self._zone["motion"] == 20
class AdvantageAirZoneMyZone(AdvantageAirEntity, BinarySensorEntity): class AdvantageAirZoneMyZone(AdvantageAirZoneEntity, BinarySensorEntity):
"""Advantage Air Zone MyZone sensor.""" """Advantage Air Zone MyZone sensor."""
_attr_entity_registry_enabled_default = False _attr_entity_registry_enabled_default = False
@ -87,9 +83,7 @@ class AdvantageAirZoneMyZone(AdvantageAirEntity, BinarySensorEntity):
"""Initialize an Advantage Air Zone MyZone sensor.""" """Initialize an Advantage Air Zone MyZone sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} myZone' self._attr_name = f'{self._zone["name"]} myZone'
self._attr_unique_id = ( self._attr_unique_id += "-myzone"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-myzone'
)
@property @property
def is_on(self): def is_on(self):

View File

@ -25,7 +25,7 @@ from .const import (
ADVANTAGE_AIR_STATE_OPEN, ADVANTAGE_AIR_STATE_OPEN,
DOMAIN as ADVANTAGE_AIR_DOMAIN, DOMAIN as ADVANTAGE_AIR_DOMAIN,
) )
from .entity import AdvantageAirEntity from .entity import AdvantageAirAcEntity, AdvantageAirZoneEntity
ADVANTAGE_AIR_HVAC_MODES = { ADVANTAGE_AIR_HVAC_MODES = {
"heat": HVACMode.HEAT, "heat": HVACMode.HEAT,
@ -87,18 +87,13 @@ async def async_setup_entry(
) )
class AdvantageAirClimateEntity(AdvantageAirEntity, ClimateEntity): class AdvantageAirAC(AdvantageAirAcEntity, ClimateEntity):
"""AdvantageAir Climate class.""" """AdvantageAir AC unit."""
_attr_temperature_unit = TEMP_CELSIUS _attr_temperature_unit = TEMP_CELSIUS
_attr_target_temperature_step = PRECISION_WHOLE _attr_target_temperature_step = PRECISION_WHOLE
_attr_max_temp = 32 _attr_max_temp = 32
_attr_min_temp = 16 _attr_min_temp = 16
class AdvantageAirAC(AdvantageAirClimateEntity):
"""AdvantageAir AC unit."""
_attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH] _attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
_attr_hvac_modes = AC_HVAC_MODES _attr_hvac_modes = AC_HVAC_MODES
_attr_supported_features = ( _attr_supported_features = (
@ -108,7 +103,6 @@ class AdvantageAirAC(AdvantageAirClimateEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an AdvantageAir AC unit.""" """Initialize an AdvantageAir AC unit."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_unique_id = f'{self.coordinator.data["system"]["rid"]}-{ac_key}'
if self._ac.get("myAutoModeEnabled"): if self._ac.get("myAutoModeEnabled"):
self._attr_hvac_modes = AC_HVAC_MODES + [HVACMode.AUTO] self._attr_hvac_modes = AC_HVAC_MODES + [HVACMode.AUTO]
@ -159,9 +153,13 @@ class AdvantageAirAC(AdvantageAirClimateEntity):
await self.async_change({self.ac_key: {"info": {"setTemp": temp}}}) await self.async_change({self.ac_key: {"info": {"setTemp": temp}}})
class AdvantageAirZone(AdvantageAirClimateEntity): class AdvantageAirZone(AdvantageAirZoneEntity, ClimateEntity):
"""AdvantageAir Zone control.""" """AdvantageAir Zone control."""
_attr_temperature_unit = TEMP_CELSIUS
_attr_target_temperature_step = PRECISION_WHOLE
_attr_max_temp = 32
_attr_min_temp = 16
_attr_hvac_modes = ZONE_HVAC_MODES _attr_hvac_modes = ZONE_HVAC_MODES
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE

View File

@ -16,7 +16,7 @@ from .const import (
ADVANTAGE_AIR_STATE_OPEN, ADVANTAGE_AIR_STATE_OPEN,
DOMAIN as ADVANTAGE_AIR_DOMAIN, DOMAIN as ADVANTAGE_AIR_DOMAIN,
) )
from .entity import AdvantageAirEntity from .entity import AdvantageAirZoneEntity
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
@ -39,7 +39,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity): class AdvantageAirZoneVent(AdvantageAirZoneEntity, CoverEntity):
"""Advantage Air Zone Vent.""" """Advantage Air Zone Vent."""
_attr_device_class = CoverDeviceClass.DAMPER _attr_device_class = CoverDeviceClass.DAMPER
@ -53,9 +53,6 @@ class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity):
"""Initialize an Advantage Air Zone Vent.""" """Initialize an Advantage Air Zone Vent."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = self._zone["name"] self._attr_name = self._zone["name"]
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}'
)
@property @property
def is_closed(self) -> bool: def is_closed(self) -> bool:

View File

@ -11,26 +11,44 @@ class AdvantageAirEntity(CoordinatorEntity):
_attr_has_entity_name = True _attr_has_entity_name = True
def __init__(self, instance, ac_key, zone_key=None): def __init__(self, instance):
"""Initialize common aspects of an Advantage Air sensor.""" """Initialize common aspects of an Advantage Air entity."""
super().__init__(instance["coordinator"]) super().__init__(instance["coordinator"])
self._attr_unique_id = self.coordinator.data["system"]["rid"]
class AdvantageAirAcEntity(AdvantageAirEntity):
"""Parent class for Advantage Air AC Entities."""
def __init__(self, instance, ac_key):
"""Initialize common aspects of an Advantage Air ac entity."""
super().__init__(instance)
self.async_change = instance["async_change"] self.async_change = instance["async_change"]
self.ac_key = ac_key self.ac_key = ac_key
self.zone_key = zone_key self._attr_unique_id += f"-{ac_key}"
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
via_device=(DOMAIN, self.coordinator.data["system"]["rid"]), via_device=(DOMAIN, self.coordinator.data["system"]["rid"]),
identifiers={ identifiers={(DOMAIN, self._attr_unique_id)},
(DOMAIN, f"{self.coordinator.data['system']['rid']}_{ac_key}")
},
manufacturer="Advantage Air", manufacturer="Advantage Air",
model=self.coordinator.data["system"]["sysType"], model=self.coordinator.data["system"]["sysType"],
name=self._ac["name"], name=self.coordinator.data["aircons"][self.ac_key]["info"]["name"],
) )
@property @property
def _ac(self): def _ac(self):
return self.coordinator.data["aircons"][self.ac_key]["info"] return self.coordinator.data["aircons"][self.ac_key]["info"]
class AdvantageAirZoneEntity(AdvantageAirAcEntity):
"""Parent class for Advantage Air Zone Entities."""
def __init__(self, instance, ac_key, zone_key):
"""Initialize common aspects of an Advantage Air zone entity."""
super().__init__(instance, ac_key)
self.zone_key = zone_key
self._attr_unique_id += f"-{zone_key}"
@property @property
def _zone(self): def _zone(self):
return self.coordinator.data["aircons"][self.ac_key]["zones"][self.zone_key] return self.coordinator.data["aircons"][self.ac_key]["zones"][self.zone_key]

View File

@ -5,7 +5,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from .entity import AdvantageAirEntity from .entity import AdvantageAirAcEntity
ADVANTAGE_AIR_INACTIVE = "Inactive" ADVANTAGE_AIR_INACTIVE = "Inactive"
@ -25,7 +25,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity): class AdvantageAirMyZone(AdvantageAirAcEntity, SelectEntity):
"""Representation of Advantage Air MyZone control.""" """Representation of Advantage Air MyZone control."""
_attr_icon = "mdi:home-thermometer" _attr_icon = "mdi:home-thermometer"
@ -37,9 +37,7 @@ class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an Advantage Air MyZone control.""" """Initialize an Advantage Air MyZone control."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_unique_id = ( self._attr_unique_id += "-myzone"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-myzone'
)
for zone in instance["coordinator"].data["aircons"][ac_key]["zones"].values(): for zone in instance["coordinator"].data["aircons"][ac_key]["zones"].values():
if zone["type"] > 0: if zone["type"] > 0:

View File

@ -16,7 +16,7 @@ from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import ADVANTAGE_AIR_STATE_OPEN, DOMAIN as ADVANTAGE_AIR_DOMAIN from .const import ADVANTAGE_AIR_STATE_OPEN, DOMAIN as ADVANTAGE_AIR_DOMAIN
from .entity import AdvantageAirEntity from .entity import AdvantageAirAcEntity, AdvantageAirZoneEntity
ADVANTAGE_AIR_SET_COUNTDOWN_VALUE = "minutes" ADVANTAGE_AIR_SET_COUNTDOWN_VALUE = "minutes"
ADVANTAGE_AIR_SET_COUNTDOWN_UNIT = "min" ADVANTAGE_AIR_SET_COUNTDOWN_UNIT = "min"
@ -56,7 +56,7 @@ async def async_setup_entry(
) )
class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity): class AdvantageAirTimeTo(AdvantageAirAcEntity, SensorEntity):
"""Representation of Advantage Air timer control.""" """Representation of Advantage Air timer control."""
_attr_native_unit_of_measurement = ADVANTAGE_AIR_SET_COUNTDOWN_UNIT _attr_native_unit_of_measurement = ADVANTAGE_AIR_SET_COUNTDOWN_UNIT
@ -68,9 +68,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
self.action = action self.action = action
self._time_key = f"countDownTo{action}" self._time_key = f"countDownTo{action}"
self._attr_name = f"Time to {action}" self._attr_name = f"Time to {action}"
self._attr_unique_id = ( self._attr_unique_id += f"-timeto{action}"
f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{action}'
)
@property @property
def native_value(self): def native_value(self):
@ -90,7 +88,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
await self.async_change({self.ac_key: {"info": {self._time_key: value}}}) await self.async_change({self.ac_key: {"info": {self._time_key: value}}})
class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity): class AdvantageAirZoneVent(AdvantageAirZoneEntity, SensorEntity):
"""Representation of Advantage Air Zone Vent Sensor.""" """Representation of Advantage Air Zone Vent Sensor."""
_attr_native_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
@ -101,9 +99,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone Vent Sensor.""" """Initialize an Advantage Air Zone Vent Sensor."""
super().__init__(instance, ac_key, zone_key=zone_key) super().__init__(instance, ac_key, zone_key=zone_key)
self._attr_name = f'{self._zone["name"]} vent' self._attr_name = f'{self._zone["name"]} vent'
self._attr_unique_id = ( self._attr_unique_id += "-vent"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-vent'
)
@property @property
def native_value(self): def native_value(self):
@ -120,7 +116,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
return "mdi:fan-off" return "mdi:fan-off"
class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity): class AdvantageAirZoneSignal(AdvantageAirZoneEntity, SensorEntity):
"""Representation of Advantage Air Zone wireless signal sensor.""" """Representation of Advantage Air Zone wireless signal sensor."""
_attr_native_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
@ -131,9 +127,7 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone wireless signal sensor.""" """Initialize an Advantage Air Zone wireless signal sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} signal' self._attr_name = f'{self._zone["name"]} signal'
self._attr_unique_id = ( self._attr_unique_id += "-signal"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-signal'
)
@property @property
def native_value(self): def native_value(self):
@ -154,7 +148,7 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
return "mdi:wifi-strength-outline" return "mdi:wifi-strength-outline"
class AdvantageAirZoneTemp(AdvantageAirEntity, SensorEntity): class AdvantageAirZoneTemp(AdvantageAirZoneEntity, SensorEntity):
"""Representation of Advantage Air Zone temperature sensor.""" """Representation of Advantage Air Zone temperature sensor."""
_attr_native_unit_of_measurement = TEMP_CELSIUS _attr_native_unit_of_measurement = TEMP_CELSIUS
@ -167,9 +161,7 @@ class AdvantageAirZoneTemp(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone Temp Sensor.""" """Initialize an Advantage Air Zone Temp Sensor."""
super().__init__(instance, ac_key, zone_key) super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} temperature' self._attr_name = f'{self._zone["name"]} temperature'
self._attr_unique_id = ( self._attr_unique_id += "-temp"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-temp'
)
@property @property
def native_value(self): def native_value(self):

View File

@ -9,7 +9,7 @@ from .const import (
ADVANTAGE_AIR_STATE_ON, ADVANTAGE_AIR_STATE_ON,
DOMAIN as ADVANTAGE_AIR_DOMAIN, DOMAIN as ADVANTAGE_AIR_DOMAIN,
) )
from .entity import AdvantageAirEntity from .entity import AdvantageAirAcEntity
async def async_setup_entry( async def async_setup_entry(
@ -28,7 +28,7 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class AdvantageAirFreshAir(AdvantageAirEntity, SwitchEntity): class AdvantageAirFreshAir(AdvantageAirAcEntity, SwitchEntity):
"""Representation of Advantage Air fresh air control.""" """Representation of Advantage Air fresh air control."""
_attr_icon = "mdi:air-filter" _attr_icon = "mdi:air-filter"
@ -37,9 +37,7 @@ class AdvantageAirFreshAir(AdvantageAirEntity, SwitchEntity):
def __init__(self, instance, ac_key): def __init__(self, instance, ac_key):
"""Initialize an Advantage Air fresh air control.""" """Initialize an Advantage Air fresh air control."""
super().__init__(instance, ac_key) super().__init__(instance, ac_key)
self._attr_unique_id = ( self._attr_unique_id += "-freshair"
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-freshair'
)
@property @property
def is_on(self): def is_on(self):