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

View File

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

View File

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

View File

@ -11,26 +11,44 @@ class AdvantageAirEntity(CoordinatorEntity):
_attr_has_entity_name = True
def __init__(self, instance, ac_key, zone_key=None):
"""Initialize common aspects of an Advantage Air sensor."""
def __init__(self, instance):
"""Initialize common aspects of an Advantage Air entity."""
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.ac_key = ac_key
self.zone_key = zone_key
self._attr_unique_id += f"-{ac_key}"
self._attr_device_info = DeviceInfo(
via_device=(DOMAIN, self.coordinator.data["system"]["rid"]),
identifiers={
(DOMAIN, f"{self.coordinator.data['system']['rid']}_{ac_key}")
},
identifiers={(DOMAIN, self._attr_unique_id)},
manufacturer="Advantage Air",
model=self.coordinator.data["system"]["sysType"],
name=self._ac["name"],
name=self.coordinator.data["aircons"][self.ac_key]["info"]["name"],
)
@property
def _ac(self):
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
def _zone(self):
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 .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
from .entity import AdvantageAirEntity
from .entity import AdvantageAirAcEntity
ADVANTAGE_AIR_INACTIVE = "Inactive"
@ -25,7 +25,7 @@ async def async_setup_entry(
async_add_entities(entities)
class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity):
class AdvantageAirMyZone(AdvantageAirAcEntity, SelectEntity):
"""Representation of Advantage Air MyZone control."""
_attr_icon = "mdi:home-thermometer"
@ -37,9 +37,7 @@ class AdvantageAirMyZone(AdvantageAirEntity, SelectEntity):
def __init__(self, instance, ac_key):
"""Initialize an Advantage Air MyZone control."""
super().__init__(instance, ac_key)
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-myzone'
)
self._attr_unique_id += "-myzone"
for zone in instance["coordinator"].data["aircons"][ac_key]["zones"].values():
if zone["type"] > 0:

View File

@ -16,7 +16,7 @@ from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
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_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."""
_attr_native_unit_of_measurement = ADVANTAGE_AIR_SET_COUNTDOWN_UNIT
@ -68,9 +68,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
self.action = action
self._time_key = f"countDownTo{action}"
self._attr_name = f"Time to {action}"
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{action}'
)
self._attr_unique_id += f"-timeto{action}"
@property
def native_value(self):
@ -90,7 +88,7 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
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."""
_attr_native_unit_of_measurement = PERCENTAGE
@ -101,9 +99,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone Vent Sensor."""
super().__init__(instance, ac_key, zone_key=zone_key)
self._attr_name = f'{self._zone["name"]} vent'
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-vent'
)
self._attr_unique_id += "-vent"
@property
def native_value(self):
@ -120,7 +116,7 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
return "mdi:fan-off"
class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
class AdvantageAirZoneSignal(AdvantageAirZoneEntity, SensorEntity):
"""Representation of Advantage Air Zone wireless signal sensor."""
_attr_native_unit_of_measurement = PERCENTAGE
@ -131,9 +127,7 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone wireless signal sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} signal'
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-signal'
)
self._attr_unique_id += "-signal"
@property
def native_value(self):
@ -154,7 +148,7 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
return "mdi:wifi-strength-outline"
class AdvantageAirZoneTemp(AdvantageAirEntity, SensorEntity):
class AdvantageAirZoneTemp(AdvantageAirZoneEntity, SensorEntity):
"""Representation of Advantage Air Zone temperature sensor."""
_attr_native_unit_of_measurement = TEMP_CELSIUS
@ -167,9 +161,7 @@ class AdvantageAirZoneTemp(AdvantageAirEntity, SensorEntity):
"""Initialize an Advantage Air Zone Temp Sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} temperature'
self._attr_unique_id = (
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-temp'
)
self._attr_unique_id += "-temp"
@property
def native_value(self):

View File

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