Remove homekit_controller's air quality entity in favor of separate sensor entities (#60480)
This commit is contained in:
parent
16462df451
commit
b8a1899d48
3 changed files with 0 additions and 214 deletions
|
@ -1,113 +0,0 @@
|
||||||
"""Support for HomeKit Controller air quality sensors."""
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
|
||||||
from aiohomekit.model.services import ServicesTypes
|
|
||||||
|
|
||||||
from homeassistant.components.air_quality import AirQualityEntity
|
|
||||||
from homeassistant.core import callback
|
|
||||||
|
|
||||||
from . import KNOWN_DEVICES, HomeKitEntity
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
AIR_QUALITY_TEXT = {
|
|
||||||
0: "unknown",
|
|
||||||
1: "excellent",
|
|
||||||
2: "good",
|
|
||||||
3: "fair",
|
|
||||||
4: "inferior",
|
|
||||||
5: "poor",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class HomeAirQualitySensor(HomeKitEntity, AirQualityEntity):
|
|
||||||
"""Representation of a HomeKit Controller Air Quality sensor."""
|
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
|
||||||
"""Call when entity is added to hass."""
|
|
||||||
_LOGGER.warning(
|
|
||||||
"The homekit_controller air_quality entity has been "
|
|
||||||
"deprecated and will be removed in 2021.12.0"
|
|
||||||
)
|
|
||||||
await super().async_added_to_hass()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
|
||||||
"""Whether or not to enable this entity by default."""
|
|
||||||
# This entity is deprecated, so don't enable by default
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_characteristic_types(self):
|
|
||||||
"""Define the homekit characteristics the entity cares about."""
|
|
||||||
return [
|
|
||||||
CharacteristicsTypes.AIR_QUALITY,
|
|
||||||
CharacteristicsTypes.DENSITY_PM25,
|
|
||||||
CharacteristicsTypes.DENSITY_PM10,
|
|
||||||
CharacteristicsTypes.DENSITY_OZONE,
|
|
||||||
CharacteristicsTypes.DENSITY_NO2,
|
|
||||||
CharacteristicsTypes.DENSITY_SO2,
|
|
||||||
CharacteristicsTypes.DENSITY_VOC,
|
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def particulate_matter_2_5(self):
|
|
||||||
"""Return the particulate matter 2.5 level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_PM25)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def particulate_matter_10(self):
|
|
||||||
"""Return the particulate matter 10 level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_PM10)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ozone(self):
|
|
||||||
"""Return the O3 (ozone) level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_OZONE)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def sulphur_dioxide(self):
|
|
||||||
"""Return the SO2 (sulphur dioxide) level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_SO2)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def nitrogen_dioxide(self):
|
|
||||||
"""Return the NO2 (nitrogen dioxide) level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_NO2)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def air_quality_text(self):
|
|
||||||
"""Return the Air Quality Index (AQI)."""
|
|
||||||
air_quality = self.service.value(CharacteristicsTypes.AIR_QUALITY)
|
|
||||||
return AIR_QUALITY_TEXT.get(air_quality, "unknown")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def volatile_organic_compounds(self):
|
|
||||||
"""Return the volatile organic compounds (VOC) level."""
|
|
||||||
return self.service.value(CharacteristicsTypes.DENSITY_VOC)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the device state attributes."""
|
|
||||||
data = {"air_quality_text": self.air_quality_text}
|
|
||||||
|
|
||||||
if voc := self.volatile_organic_compounds:
|
|
||||||
data["volatile_organic_compounds"] = voc
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
||||||
"""Set up Homekit air quality sensor."""
|
|
||||||
hkid = config_entry.data["AccessoryPairingID"]
|
|
||||||
conn = hass.data[KNOWN_DEVICES][hkid]
|
|
||||||
|
|
||||||
@callback
|
|
||||||
def async_add_service(service):
|
|
||||||
if service.short_type != ServicesTypes.AIR_QUALITY_SENSOR:
|
|
||||||
return False
|
|
||||||
info = {"aid": service.accessory.aid, "iid": service.iid}
|
|
||||||
async_add_entities([HomeAirQualitySensor(conn, info)], True)
|
|
||||||
return True
|
|
||||||
|
|
||||||
conn.add_listener(async_add_service)
|
|
|
@ -40,7 +40,6 @@ HOMEKIT_ACCESSORY_DISPATCH = {
|
||||||
"leak": "binary_sensor",
|
"leak": "binary_sensor",
|
||||||
"fan": "fan",
|
"fan": "fan",
|
||||||
"fanv2": "fan",
|
"fanv2": "fan",
|
||||||
"air-quality": "air_quality",
|
|
||||||
"occupancy": "binary_sensor",
|
"occupancy": "binary_sensor",
|
||||||
"television": "media_player",
|
"television": "media_player",
|
||||||
"valve": "switch",
|
"valve": "switch",
|
||||||
|
|
|
@ -1,100 +0,0 @@
|
||||||
"""Basic checks for HomeKit air quality sensor."""
|
|
||||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
|
||||||
from aiohomekit.model.services import ServicesTypes
|
|
||||||
|
|
||||||
from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
|
||||||
from homeassistant.helpers import entity_registry as er
|
|
||||||
|
|
||||||
from tests.components.homekit_controller.common import setup_test_component
|
|
||||||
|
|
||||||
|
|
||||||
def create_air_quality_sensor_service(accessory):
|
|
||||||
"""Define temperature characteristics."""
|
|
||||||
service = accessory.add_service(ServicesTypes.AIR_QUALITY_SENSOR)
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.AIR_QUALITY)
|
|
||||||
cur_state.value = 5
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_OZONE)
|
|
||||||
cur_state.value = 1111
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_NO2)
|
|
||||||
cur_state.value = 2222
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_SO2)
|
|
||||||
cur_state.value = 3333
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_PM25)
|
|
||||||
cur_state.value = 4444
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_PM10)
|
|
||||||
cur_state.value = 5555
|
|
||||||
|
|
||||||
cur_state = service.add_char(CharacteristicsTypes.DENSITY_VOC)
|
|
||||||
cur_state.value = 6666
|
|
||||||
|
|
||||||
|
|
||||||
async def test_air_quality_sensor_read_state(hass, utcnow):
|
|
||||||
"""Test reading the state of a HomeKit temperature sensor accessory."""
|
|
||||||
helper = await setup_test_component(hass, create_air_quality_sensor_service)
|
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
entity_registry.async_update_entity(
|
|
||||||
entity_id="air_quality.testdevice", disabled_by=None
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = await helper.poll_and_get_state()
|
|
||||||
assert state.state == "4444"
|
|
||||||
|
|
||||||
assert state.attributes["air_quality_text"] == "poor"
|
|
||||||
assert state.attributes["ozone"] == 1111
|
|
||||||
assert state.attributes["nitrogen_dioxide"] == 2222
|
|
||||||
assert state.attributes["sulphur_dioxide"] == 3333
|
|
||||||
assert state.attributes["particulate_matter_2_5"] == 4444
|
|
||||||
assert state.attributes["particulate_matter_10"] == 5555
|
|
||||||
assert state.attributes["volatile_organic_compounds"] == 6666
|
|
||||||
|
|
||||||
|
|
||||||
async def test_air_quality_sensor_read_state_even_if_air_quality_off(hass, utcnow):
|
|
||||||
"""The air quality entity is disabled by default, the replacement sensors should always be available."""
|
|
||||||
await setup_test_component(hass, create_air_quality_sensor_service)
|
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
|
||||||
|
|
||||||
sensors = [
|
|
||||||
{"entity_id": "sensor.testdevice_air_quality"},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_pm10_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_pm2_5_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_pm10_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_ozone_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_sulphur_dioxide_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_nitrogen_dioxide_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"entity_id": "sensor.testdevice_volatile_organic_compound_density",
|
|
||||||
"units": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
for sensor in sensors:
|
|
||||||
entry = entity_registry.async_get(sensor["entity_id"])
|
|
||||||
assert entry is not None
|
|
||||||
assert entry.unit_of_measurement == sensor.get("units")
|
|
Loading…
Add table
Add a link
Reference in a new issue