Make AirNow use device class (#94986)

This commit is contained in:
Joost Lekkerkerker 2023-06-22 15:58:14 +02:00 committed by GitHub
parent e4c8a94aaf
commit c503becd9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 9 deletions

View File

@ -6,6 +6,7 @@ from dataclasses import dataclass
from typing import Any from typing import Any
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
@ -57,10 +58,9 @@ class AirNowEntityDescription(SensorEntityDescription, AirNowEntityDescriptionMi
SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = ( SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
AirNowEntityDescription( AirNowEntityDescription(
key=ATTR_API_AQI, key=ATTR_API_AQI,
translation_key="aqi",
icon="mdi:blur", icon="mdi:blur",
native_unit_of_measurement="aqi",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.AQI,
value_fn=lambda data: data.get(ATTR_API_AQI), value_fn=lambda data: data.get(ATTR_API_AQI),
extra_state_attributes_fn=lambda data: { extra_state_attributes_fn=lambda data: {
ATTR_DESCR: data[ATTR_API_AQI_DESCRIPTION], ATTR_DESCR: data[ATTR_API_AQI_DESCRIPTION],
@ -69,10 +69,10 @@ SENSOR_TYPES: tuple[AirNowEntityDescription, ...] = (
), ),
AirNowEntityDescription( AirNowEntityDescription(
key=ATTR_API_PM25, key=ATTR_API_PM25,
translation_key="pm25",
icon="mdi:blur", icon="mdi:blur",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM25,
value_fn=lambda data: data.get(ATTR_API_PM25), value_fn=lambda data: data.get(ATTR_API_PM25),
extra_state_attributes_fn=None, extra_state_attributes_fn=None,
), ),

View File

@ -23,12 +23,6 @@
}, },
"entity": { "entity": {
"sensor": { "sensor": {
"aqi": {
"name": "[%key:component::sensor::entity_component::aqi::name%]"
},
"pm25": {
"name": "[%key:component::sensor::entity_component::pm25::name%]"
},
"o3": { "o3": {
"name": "[%key:component::sensor::entity_component::ozone::name%]" "name": "[%key:component::sensor::entity_component::ozone::name%]"
} }