Remove deprecated WAQI state attributes (#116595)
This commit is contained in:
parent
8c053a351c
commit
f92fb0f492
2 changed files with 6 additions and 52 deletions
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable, Mapping
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from aiowaqi import WAQIAirQuality
|
from aiowaqi import WAQIAirQuality
|
||||||
from aiowaqi.models import Pollutant
|
from aiowaqi.models import Pollutant
|
||||||
|
@ -17,13 +16,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import PERCENTAGE, UnitOfPressure, UnitOfTemperature
|
||||||
ATTR_TEMPERATURE,
|
|
||||||
ATTR_TIME,
|
|
||||||
PERCENTAGE,
|
|
||||||
UnitOfPressure,
|
|
||||||
UnitOfTemperature,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -49,7 +42,7 @@ ATTR_SULFUR_DIOXIDE = "sulfur_dioxide"
|
||||||
class WAQISensorEntityDescription(SensorEntityDescription):
|
class WAQISensorEntityDescription(SensorEntityDescription):
|
||||||
"""Describes WAQI sensor entity."""
|
"""Describes WAQI sensor entity."""
|
||||||
|
|
||||||
available_fn: Callable[[WAQIAirQuality], bool]
|
available_fn: Callable[[WAQIAirQuality], bool] = lambda _: True
|
||||||
value_fn: Callable[[WAQIAirQuality], StateType]
|
value_fn: Callable[[WAQIAirQuality], StateType]
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +52,6 @@ SENSORS: list[WAQISensorEntityDescription] = [
|
||||||
device_class=SensorDeviceClass.AQI,
|
device_class=SensorDeviceClass.AQI,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
value_fn=lambda aq: aq.air_quality_index,
|
value_fn=lambda aq: aq.air_quality_index,
|
||||||
available_fn=lambda _: True,
|
|
||||||
),
|
),
|
||||||
WAQISensorEntityDescription(
|
WAQISensorEntityDescription(
|
||||||
key="humidity",
|
key="humidity",
|
||||||
|
@ -141,7 +133,6 @@ SENSORS: list[WAQISensorEntityDescription] = [
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=[pollutant.value for pollutant in Pollutant],
|
options=[pollutant.value for pollutant in Pollutant],
|
||||||
value_fn=lambda aq: aq.dominant_pollutant,
|
value_fn=lambda aq: aq.dominant_pollutant,
|
||||||
available_fn=lambda _: True,
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -152,11 +143,9 @@ async def async_setup_entry(
|
||||||
"""Set up the WAQI sensor."""
|
"""Set up the WAQI sensor."""
|
||||||
coordinator: WAQIDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator: WAQIDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
WaqiSensor(coordinator, sensor)
|
||||||
WaqiSensor(coordinator, sensor)
|
for sensor in SENSORS
|
||||||
for sensor in SENSORS
|
if sensor.available_fn(coordinator.data)
|
||||||
if sensor.available_fn(coordinator.data)
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,28 +177,3 @@ class WaqiSensor(CoordinatorEntity[WAQIDataUpdateCoordinator], SensorEntity):
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self.entity_description.value_fn(self.coordinator.data)
|
return self.entity_description.value_fn(self.coordinator.data)
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
|
||||||
"""Return old state attributes if the entity is AQI entity."""
|
|
||||||
# These are deprecated and will be removed in 2024.5
|
|
||||||
if self.entity_description.key != "air_quality":
|
|
||||||
return None
|
|
||||||
attrs: dict[str, Any] = {}
|
|
||||||
attrs[ATTR_TIME] = self.coordinator.data.measured_at
|
|
||||||
attrs[ATTR_DOMINENTPOL] = self.coordinator.data.dominant_pollutant
|
|
||||||
|
|
||||||
iaqi = self.coordinator.data.extended_air_quality
|
|
||||||
|
|
||||||
attribute = {
|
|
||||||
ATTR_PM2_5: iaqi.pm25,
|
|
||||||
ATTR_PM10: iaqi.pm10,
|
|
||||||
ATTR_HUMIDITY: iaqi.humidity,
|
|
||||||
ATTR_PRESSURE: iaqi.pressure,
|
|
||||||
ATTR_TEMPERATURE: iaqi.temperature,
|
|
||||||
ATTR_OZONE: iaqi.ozone,
|
|
||||||
ATTR_NITROGEN_DIOXIDE: iaqi.nitrogen_dioxide,
|
|
||||||
ATTR_SULFUR_DIOXIDE: iaqi.sulfur_dioxide,
|
|
||||||
}
|
|
||||||
res_attributes = {k: v for k, v in attribute.items() if v is not None}
|
|
||||||
return {**attrs, **res_attributes}
|
|
||||||
|
|
|
@ -4,18 +4,8 @@
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'attribution': 'RIVM - Rijksinstituut voor Volksgezondheid en Milieum, Landelijk Meetnet Luchtkwaliteit and World Air Quality Index Project',
|
'attribution': 'RIVM - Rijksinstituut voor Volksgezondheid en Milieum, Landelijk Meetnet Luchtkwaliteit and World Air Quality Index Project',
|
||||||
'device_class': 'aqi',
|
'device_class': 'aqi',
|
||||||
'dominentpol': <Pollutant.OZONE: 'o3'>,
|
|
||||||
'friendly_name': 'de Jongweg, Utrecht Air quality index',
|
'friendly_name': 'de Jongweg, Utrecht Air quality index',
|
||||||
'humidity': 80,
|
|
||||||
'nitrogen_dioxide': 2.3,
|
|
||||||
'ozone': 29.4,
|
|
||||||
'pm_10': 12,
|
|
||||||
'pm_2_5': 17,
|
|
||||||
'pressure': 1008.8,
|
|
||||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||||
'sulfur_dioxide': 2.3,
|
|
||||||
'temperature': 16,
|
|
||||||
'time': datetime.datetime(2023, 8, 7, 17, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))),
|
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.de_jongweg_utrecht_air_quality_index',
|
'entity_id': 'sensor.de_jongweg_utrecht_air_quality_index',
|
||||||
|
|
Loading…
Add table
Reference in a new issue