mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Use entity class attributes for advantage_air (#52498)
* Use entity class attributes for advantage_air * update * tweak * tweak * use update listeners
This commit is contained in:
parent
72a3860361
commit
16e8373fdd
@ -35,15 +35,13 @@ class AdvantageAirZoneFilter(AdvantageAirEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_PROBLEM
|
_attr_device_class = DEVICE_CLASS_PROBLEM
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key):
|
||||||
def name(self):
|
"""Initialize an Advantage Air Filter."""
|
||||||
"""Return the name."""
|
super().__init__(instance, ac_key)
|
||||||
return f'{self._ac["name"]} Filter'
|
self._attr_name = f'{self._ac["name"]} Filter'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-filter'
|
||||||
def unique_id(self):
|
)
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-filter'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@ -56,15 +54,13 @@ class AdvantageAirZoneMotion(AdvantageAirEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_device_class = DEVICE_CLASS_MOTION
|
_attr_device_class = DEVICE_CLASS_MOTION
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def name(self):
|
"""Initialize an Advantage Air Zone Motion."""
|
||||||
"""Return the name."""
|
super().__init__(instance, ac_key, zone_key)
|
||||||
return f'{self._zone["name"]} Motion'
|
self._attr_name = f'{self._zone["name"]} Motion'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-motion'
|
||||||
def unique_id(self):
|
)
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}-motion'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@ -77,15 +73,13 @@ class AdvantageAirZoneMyZone(AdvantageAirEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_entity_registry_enabled_default = False
|
_attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def name(self):
|
"""Initialize an Advantage Air Zone MyZone."""
|
||||||
"""Return the name."""
|
super().__init__(instance, ac_key, zone_key)
|
||||||
return f'{self._zone["name"]} MyZone'
|
self._attr_name = f'{self._zone["name"]} MyZone'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-myzone'
|
||||||
def unique_id(self):
|
)
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}-myzone'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Climate platform for Advantage Air integration."""
|
"""Climate platform for Advantage Air integration."""
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
@ -16,6 +15,7 @@ from homeassistant.components.climate.const import (
|
|||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
|
||||||
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -84,39 +84,26 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AdvantageAirClimateEntity(AdvantageAirEntity, ClimateEntity):
|
class AdvantageAirClimateEntity(AdvantageAirEntity, ClimateEntity):
|
||||||
"""AdvantageAir Climate class."""
|
"""AdvantageAir Climate class."""
|
||||||
|
|
||||||
@property
|
_attr_temperature_unit = TEMP_CELSIUS
|
||||||
def temperature_unit(self):
|
_attr_target_temperature_step = PRECISION_WHOLE
|
||||||
"""Return the temperature unit."""
|
_attr_max_temp = 32
|
||||||
return TEMP_CELSIUS
|
_attr_min_temp = 16
|
||||||
|
|
||||||
@property
|
|
||||||
def target_temperature_step(self):
|
|
||||||
"""Return the supported temperature step."""
|
|
||||||
return PRECISION_WHOLE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_temp(self):
|
|
||||||
"""Return the maximum supported temperature."""
|
|
||||||
return 32
|
|
||||||
|
|
||||||
@property
|
|
||||||
def min_temp(self):
|
|
||||||
"""Return the minimum supported temperature."""
|
|
||||||
return 16
|
|
||||||
|
|
||||||
|
|
||||||
class AdvantageAirAC(AdvantageAirClimateEntity):
|
class AdvantageAirAC(AdvantageAirClimateEntity):
|
||||||
"""AdvantageAir AC unit."""
|
"""AdvantageAir AC unit."""
|
||||||
|
|
||||||
@property
|
_attr_fan_modes = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
|
||||||
def name(self):
|
_attr_hvac_modes = AC_HVAC_MODES
|
||||||
"""Return the name."""
|
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
|
||||||
return self._ac["name"]
|
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key):
|
||||||
def unique_id(self):
|
"""Initialize an AdvantageAir AC unit."""
|
||||||
"""Return a unique id."""
|
super().__init__(instance, ac_key)
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}'
|
self._attr_name = self._ac["name"]
|
||||||
|
self._attr_unique_id = f'{self.coordinator.data["system"]["rid"]}-{ac_key}'
|
||||||
|
if self._ac.get("myAutoModeEnabled"):
|
||||||
|
self._attr_hvac_modes = AC_HVAC_MODES + [HVAC_MODE_AUTO]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
@ -130,28 +117,11 @@ class AdvantageAirAC(AdvantageAirClimateEntity):
|
|||||||
return ADVANTAGE_AIR_HVAC_MODES.get(self._ac["mode"])
|
return ADVANTAGE_AIR_HVAC_MODES.get(self._ac["mode"])
|
||||||
return HVAC_MODE_OFF
|
return HVAC_MODE_OFF
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return the supported HVAC modes."""
|
|
||||||
if self._ac.get("myAutoModeEnabled"):
|
|
||||||
return AC_HVAC_MODES + [HVAC_MODE_AUTO]
|
|
||||||
return AC_HVAC_MODES
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self):
|
||||||
"""Return the current fan modes."""
|
"""Return the current fan modes."""
|
||||||
return ADVANTAGE_AIR_FAN_MODES.get(self._ac["fan"])
|
return ADVANTAGE_AIR_FAN_MODES.get(self._ac["fan"])
|
||||||
|
|
||||||
@property
|
|
||||||
def fan_modes(self):
|
|
||||||
"""Return the supported fan modes."""
|
|
||||||
return [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the supported features."""
|
|
||||||
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE
|
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode):
|
||||||
"""Set the HVAC Mode and State."""
|
"""Set the HVAC Mode and State."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVAC_MODE_OFF:
|
||||||
@ -185,42 +155,30 @@ class AdvantageAirAC(AdvantageAirClimateEntity):
|
|||||||
class AdvantageAirZone(AdvantageAirClimateEntity):
|
class AdvantageAirZone(AdvantageAirClimateEntity):
|
||||||
"""AdvantageAir Zone control."""
|
"""AdvantageAir Zone control."""
|
||||||
|
|
||||||
@property
|
_attr_hvac_modes = ZONE_HVAC_MODES
|
||||||
def name(self):
|
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE
|
||||||
"""Return the name."""
|
|
||||||
return self._zone["name"]
|
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def unique_id(self):
|
"""Initialize an AdvantageAir Zone control."""
|
||||||
"""Return a unique id."""
|
super().__init__(instance, ac_key, zone_key)
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}'
|
self._attr_name = self._zone["name"]
|
||||||
|
self._attr_unique_id = (
|
||||||
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}'
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
async def async_added_to_hass(self):
|
||||||
def current_temperature(self):
|
"""When entity is added to hass."""
|
||||||
"""Return the current temperature."""
|
self.async_on_remove(self.coordinator.async_add_listener(self._update_callback))
|
||||||
return self._zone["measuredTemp"]
|
|
||||||
|
|
||||||
@property
|
@callback
|
||||||
def target_temperature(self):
|
def _update_callback(self) -> None:
|
||||||
"""Return the target temperature."""
|
"""Load data from integration."""
|
||||||
return self._zone["setTemp"]
|
self._attr_current_temperature = self._zone["measuredTemp"]
|
||||||
|
self._attr_target_temperature = self._zone["setTemp"]
|
||||||
@property
|
self._attr_hvac_mode = HVAC_MODE_OFF
|
||||||
def hvac_mode(self):
|
|
||||||
"""Return the current HVAC modes."""
|
|
||||||
if self._zone["state"] == ADVANTAGE_AIR_STATE_OPEN:
|
if self._zone["state"] == ADVANTAGE_AIR_STATE_OPEN:
|
||||||
return HVAC_MODE_FAN_ONLY
|
self._attr_hvac_mode = HVAC_MODE_FAN_ONLY
|
||||||
return HVAC_MODE_OFF
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return supported HVAC modes."""
|
|
||||||
return ZONE_HVAC_MODES
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the supported features."""
|
|
||||||
return SUPPORT_TARGET_TEMPERATURE
|
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode):
|
async def async_set_hvac_mode(self, hvac_mode):
|
||||||
"""Set the HVAC Mode and State."""
|
"""Set the HVAC Mode and State."""
|
||||||
|
@ -36,25 +36,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity):
|
class AdvantageAirZoneVent(AdvantageAirEntity, CoverEntity):
|
||||||
"""Advantage Air Cover Class."""
|
"""Advantage Air Cover Class."""
|
||||||
|
|
||||||
@property
|
_attr_device_class = DEVICE_CLASS_DAMPER
|
||||||
def name(self):
|
_attr_supported_features = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
||||||
"""Return the name."""
|
|
||||||
return f'{self._zone["name"]}'
|
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def unique_id(self):
|
"""Initialize an Advantage Air Cover Class."""
|
||||||
"""Return a unique id."""
|
super().__init__(instance, ac_key, zone_key)
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}'
|
self._attr_name = f'{self._zone["name"]}'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}'
|
||||||
def device_class(self):
|
)
|
||||||
"""Return the device class of the vent."""
|
|
||||||
return DEVICE_CLASS_DAMPER
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Return the supported features."""
|
|
||||||
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
|
@ -14,6 +14,13 @@ class AdvantageAirEntity(CoordinatorEntity):
|
|||||||
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.zone_key = zone_key
|
||||||
|
self._attr_device_info = {
|
||||||
|
"identifiers": {(DOMAIN, self.coordinator.data["system"]["rid"])},
|
||||||
|
"name": self.coordinator.data["system"]["name"],
|
||||||
|
"manufacturer": "Advantage Air",
|
||||||
|
"model": self.coordinator.data["system"]["sysType"],
|
||||||
|
"sw_version": self.coordinator.data["system"]["myAppRev"],
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _ac(self):
|
def _ac(self):
|
||||||
@ -22,14 +29,3 @@ class AdvantageAirEntity(CoordinatorEntity):
|
|||||||
@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]
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return parent device information."""
|
|
||||||
return {
|
|
||||||
"identifiers": {(DOMAIN, self.coordinator.data["system"]["rid"])},
|
|
||||||
"name": self.coordinator.data["system"]["name"],
|
|
||||||
"manufacturer": "Advantage Air",
|
|
||||||
"model": self.coordinator.data["system"]["sysType"],
|
|
||||||
"sw_version": self.coordinator.data["system"]["myAppRev"],
|
|
||||||
}
|
|
||||||
|
@ -51,17 +51,11 @@ class AdvantageAirTimeTo(AdvantageAirEntity, SensorEntity):
|
|||||||
"""Initialize the Advantage Air timer control."""
|
"""Initialize the Advantage Air timer control."""
|
||||||
super().__init__(instance, ac_key)
|
super().__init__(instance, ac_key)
|
||||||
self.action = action
|
self.action = action
|
||||||
self._time_key = f"countDownTo{self.action}"
|
self._time_key = f"countDownTo{action}"
|
||||||
|
self._attr_name = f'{self._ac["name"]} Time To {action}'
|
||||||
@property
|
self._attr_unique_id = (
|
||||||
def name(self):
|
f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{action}'
|
||||||
"""Return the name."""
|
)
|
||||||
return f'{self._ac["name"]} Time To {self.action}'
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-timeto{self.action}'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -87,15 +81,13 @@ class AdvantageAirZoneVent(AdvantageAirEntity, SensorEntity):
|
|||||||
_attr_unit_of_measurement = PERCENTAGE
|
_attr_unit_of_measurement = PERCENTAGE
|
||||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def name(self):
|
"""Initialize an Advantage Air Zone Vent Sensor."""
|
||||||
"""Return the name."""
|
super().__init__(instance, ac_key, zone_key=zone_key)
|
||||||
return f'{self._zone["name"]} Vent'
|
self._attr_name = f'{self._zone["name"]} Vent'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-vent'
|
||||||
def unique_id(self):
|
)
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}-vent'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -118,15 +110,13 @@ class AdvantageAirZoneSignal(AdvantageAirEntity, SensorEntity):
|
|||||||
_attr_unit_of_measurement = PERCENTAGE
|
_attr_unit_of_measurement = PERCENTAGE
|
||||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key, zone_key):
|
||||||
def name(self):
|
"""Initialize an Advantage Air Zone wireless signal sensor."""
|
||||||
"""Return the name."""
|
super().__init__(instance, ac_key, zone_key=zone_key)
|
||||||
return f'{self._zone["name"]} Signal'
|
self._attr_name = f'{self._zone["name"]} Signal'
|
||||||
|
self._attr_unique_id = (
|
||||||
@property
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-{zone_key}-signal'
|
||||||
def unique_id(self):
|
)
|
||||||
"""Return a unique id."""
|
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-{self.zone_key}-signal'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -25,26 +25,21 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
class AdvantageAirFreshAir(AdvantageAirEntity, ToggleEntity):
|
class AdvantageAirFreshAir(AdvantageAirEntity, ToggleEntity):
|
||||||
"""Representation of Advantage Air fresh air control."""
|
"""Representation of Advantage Air fresh air control."""
|
||||||
|
|
||||||
@property
|
_attr_icon = "mdi:air-filter"
|
||||||
def name(self):
|
|
||||||
"""Return the name."""
|
|
||||||
return f'{self._ac["name"]} Fresh Air'
|
|
||||||
|
|
||||||
@property
|
def __init__(self, instance, ac_key):
|
||||||
def unique_id(self):
|
"""Initialize an Advantage Air fresh air control."""
|
||||||
"""Return a unique id."""
|
super().__init__(instance, ac_key)
|
||||||
return f'{self.coordinator.data["system"]["rid"]}-{self.ac_key}-freshair'
|
self._attr_name = f'{self._ac["name"]} Fresh Air'
|
||||||
|
self._attr_unique_id = (
|
||||||
|
f'{self.coordinator.data["system"]["rid"]}-{ac_key}-freshair'
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return the fresh air status."""
|
"""Return the fresh air status."""
|
||||||
return self._ac["freshAirStatus"] == ADVANTAGE_AIR_STATE_ON
|
return self._ac["freshAirStatus"] == ADVANTAGE_AIR_STATE_ON
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return a representative icon of the fresh air switch."""
|
|
||||||
return "mdi:air-filter"
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn fresh air on."""
|
"""Turn fresh air on."""
|
||||||
await self.async_change(
|
await self.async_change(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user