|
|
|
|
@@ -30,7 +30,9 @@ from .const import DOMAIN
|
|
|
|
|
class AirVisualProMeasurementKeyMixin:
|
|
|
|
|
"""Define an entity description mixin to include a measurement key."""
|
|
|
|
|
|
|
|
|
|
value_fn: Callable[[dict[str, Any], dict[str, Any], dict[str, Any]], float | int]
|
|
|
|
|
value_fn: Callable[
|
|
|
|
|
[dict[str, Any], dict[str, Any], dict[str, Any], dict[str, Any]], float | int
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
@@ -45,29 +47,42 @@ SENSOR_DESCRIPTIONS = (
|
|
|
|
|
key="air_quality_index",
|
|
|
|
|
device_class=SensorDeviceClass.AQI,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements[
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements[
|
|
|
|
|
async_get_aqi_locale(settings)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="outdoor_air_quality_index",
|
|
|
|
|
device_class=SensorDeviceClass.AQI,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: int(
|
|
|
|
|
history.get(
|
|
|
|
|
f'Outdoor {"AQI(US)" if settings["is_aqi_usa"] else "AQI(CN)"}', -1
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
translation_key="outdoor_air_quality_index",
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="battery_level",
|
|
|
|
|
device_class=SensorDeviceClass.BATTERY,
|
|
|
|
|
entity_category=EntityCategory.DIAGNOSTIC,
|
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
|
|
|
value_fn=lambda settings, status, measurements: status["battery"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: status["battery"],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="carbon_dioxide",
|
|
|
|
|
device_class=SensorDeviceClass.CO2,
|
|
|
|
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["co2"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements["co2"],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="humidity",
|
|
|
|
|
device_class=SensorDeviceClass.HUMIDITY,
|
|
|
|
|
native_unit_of_measurement=PERCENTAGE,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["humidity"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements[
|
|
|
|
|
"humidity"
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="particulate_matter_0_1",
|
|
|
|
|
@@ -75,7 +90,7 @@ SENSOR_DESCRIPTIONS = (
|
|
|
|
|
device_class=SensorDeviceClass.PM1,
|
|
|
|
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["pm0_1"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements["pm0_1"],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="particulate_matter_1_0",
|
|
|
|
|
@@ -83,28 +98,30 @@ SENSOR_DESCRIPTIONS = (
|
|
|
|
|
device_class=SensorDeviceClass.PM10,
|
|
|
|
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["pm1_0"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements["pm1_0"],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="particulate_matter_2_5",
|
|
|
|
|
device_class=SensorDeviceClass.PM25,
|
|
|
|
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["pm2_5"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements["pm2_5"],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="temperature",
|
|
|
|
|
device_class=SensorDeviceClass.TEMPERATURE,
|
|
|
|
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["temperature_C"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements[
|
|
|
|
|
"temperature_C"
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
AirVisualProMeasurementDescription(
|
|
|
|
|
key="voc",
|
|
|
|
|
device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
|
|
|
|
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
|
|
|
|
state_class=SensorStateClass.MEASUREMENT,
|
|
|
|
|
value_fn=lambda settings, status, measurements: measurements["voc"],
|
|
|
|
|
value_fn=lambda settings, status, measurements, history: measurements["voc"],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -143,4 +160,5 @@ class AirVisualProSensor(AirVisualProEntity, SensorEntity):
|
|
|
|
|
self.coordinator.data["settings"],
|
|
|
|
|
self.coordinator.data["status"],
|
|
|
|
|
self.coordinator.data["measurements"],
|
|
|
|
|
self.coordinator.data["history"],
|
|
|
|
|
)
|
|
|
|
|
|