Use PM1, PM25 and PM10 device classes in Nettigo Air Monitor integration (#54741)

pull/54748/head
Maciej Bieniek 2021-08-17 10:49:22 +02:00 committed by GitHub
parent 6d7ad8903f
commit 4f3d1c5e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 12 deletions

View File

@ -13,6 +13,9 @@ from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
DEVICE_CLASS_CO2,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_TEMPERATURE,
@ -122,14 +125,14 @@ SENSORS: Final[tuple[SensorEntityDescription, ...]] = (
key=ATTR_SDS011_P1,
name=f"{DEFAULT_NAME} SDS011 Particulate Matter 10",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SDS011_P2,
name=f"{DEFAULT_NAME} SDS011 Particulate Matter 2.5",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
@ -150,28 +153,28 @@ SENSORS: Final[tuple[SensorEntityDescription, ...]] = (
key=ATTR_SPS30_P0,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 1.0",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
device_class=DEVICE_CLASS_PM1,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P1,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 10",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
device_class=DEVICE_CLASS_PM10,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P2,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 2.5",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
device_class=DEVICE_CLASS_PM25,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P4,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 4.0",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
icon="mdi:molecule",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(

View File

@ -19,6 +19,9 @@ from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
DEVICE_CLASS_CO2,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_PM1,
DEVICE_CLASS_PM10,
DEVICE_CLASS_PM25,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_SIGNAL_STRENGTH,
DEVICE_CLASS_TEMPERATURE,
@ -212,12 +215,12 @@ async def test_sensor(hass):
state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_10")
assert state
assert state.state == "19"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM10
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get(
"sensor.nettigo_air_monitor_sds011_particulate_matter_10"
@ -228,12 +231,12 @@ async def test_sensor(hass):
state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_2_5")
assert state
assert state.state == "11"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM25
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get(
"sensor.nettigo_air_monitor_sds011_particulate_matter_2_5"
@ -244,12 +247,12 @@ async def test_sensor(hass):
state = hass.states.get("sensor.nettigo_air_monitor_sps30_particulate_matter_1_0")
assert state
assert state.state == "31"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM1
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get(
"sensor.nettigo_air_monitor_sps30_particulate_matter_1_0"
@ -260,12 +263,12 @@ async def test_sensor(hass):
state = hass.states.get("sensor.nettigo_air_monitor_sps30_particulate_matter_10")
assert state
assert state.state == "21"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM10
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_particulate_matter_10")
assert entry
@ -274,12 +277,12 @@ async def test_sensor(hass):
state = hass.states.get("sensor.nettigo_air_monitor_sps30_particulate_matter_2_5")
assert state
assert state.state == "34"
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM25
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
entry = registry.async_get(
"sensor.nettigo_air_monitor_sps30_particulate_matter_2_5"
@ -295,7 +298,7 @@ async def test_sensor(hass):
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
assert state.attributes.get(ATTR_ICON) == "mdi:molecule"
entry = registry.async_get(
"sensor.nettigo_air_monitor_sps30_particulate_matter_4_0"