Add support for PMSx003 sensors in NAM integration (#81289)

* Add support for PMSx003

* Organize the order of tests
pull/81295/head
Maciej Bieniek 2022-10-31 10:22:45 +01:00 committed by GitHub
parent 47a0f89ada
commit ae2419b569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 27 deletions

View File

@ -22,6 +22,12 @@ ATTR_DHT22_TEMPERATURE: Final = "dht22_temperature"
ATTR_HECA_HUMIDITY: Final = "heca_humidity" ATTR_HECA_HUMIDITY: Final = "heca_humidity"
ATTR_HECA_TEMPERATURE: Final = "heca_temperature" ATTR_HECA_TEMPERATURE: Final = "heca_temperature"
ATTR_MHZ14A_CARBON_DIOXIDE: Final = "mhz14a_carbon_dioxide" ATTR_MHZ14A_CARBON_DIOXIDE: Final = "mhz14a_carbon_dioxide"
ATTR_PMSX003: Final = "pms"
ATTR_PMSX003_CAQI: Final = f"{ATTR_PMSX003}{SUFFIX_CAQI}"
ATTR_PMSX003_CAQI_LEVEL: Final = f"{ATTR_PMSX003}{SUFFIX_CAQI}_level"
ATTR_PMSX003_P0: Final = f"{ATTR_PMSX003}{SUFFIX_P0}"
ATTR_PMSX003_P1: Final = f"{ATTR_PMSX003}{SUFFIX_P1}"
ATTR_PMSX003_P2: Final = f"{ATTR_PMSX003}{SUFFIX_P2}"
ATTR_SDS011: Final = "sds011" ATTR_SDS011: Final = "sds011"
ATTR_SDS011_CAQI: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}" ATTR_SDS011_CAQI: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}"
ATTR_SDS011_CAQI_LEVEL: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}_level" ATTR_SDS011_CAQI_LEVEL: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}_level"

View File

@ -43,6 +43,11 @@ from .const import (
ATTR_HECA_HUMIDITY, ATTR_HECA_HUMIDITY,
ATTR_HECA_TEMPERATURE, ATTR_HECA_TEMPERATURE,
ATTR_MHZ14A_CARBON_DIOXIDE, ATTR_MHZ14A_CARBON_DIOXIDE,
ATTR_PMSX003_CAQI,
ATTR_PMSX003_CAQI_LEVEL,
ATTR_PMSX003_P0,
ATTR_PMSX003_P1,
ATTR_PMSX003_P2,
ATTR_SDS011_CAQI, ATTR_SDS011_CAQI,
ATTR_SDS011_CAQI_LEVEL, ATTR_SDS011_CAQI_LEVEL,
ATTR_SDS011_P1, ATTR_SDS011_P1,
@ -136,6 +141,38 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
device_class=SensorDeviceClass.CO2, device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SensorEntityDescription(
key=ATTR_PMSX003_CAQI,
name="PMSx003 CAQI",
icon="mdi:air-filter",
),
SensorEntityDescription(
key=ATTR_PMSX003_CAQI_LEVEL,
name="PMSx003 CAQI level",
icon="mdi:air-filter",
device_class="nam__caqi_level",
),
SensorEntityDescription(
key=ATTR_PMSX003_P0,
name="PMSx003 particulate matter 1.0",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM1,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_PMSX003_P1,
name="PMSx003 particulate matter 10",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM10,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_PMSX003_P2,
name="PMSx003 particulate matter 2.5",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM25,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription( SensorEntityDescription(
key=ATTR_SDS011_CAQI, key=ATTR_SDS011_CAQI,
name="SDS011 CAQI", name="SDS011 CAQI",

View File

@ -228,6 +228,73 @@ async def test_sensor(hass):
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-uptime" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-uptime"
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_caqi_level")
assert state
assert state.state == "very low"
assert state.attributes.get(ATTR_DEVICE_CLASS) == "nam__caqi_level"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_pmsx003_caqi_level")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_caqi_level"
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_caqi")
assert state
assert state.state == "19"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_pmsx003_caqi")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_caqi"
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_particulate_matter_10")
assert state
assert state.state == "10"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM10
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get(
"sensor.nettigo_air_monitor_pmsx003_particulate_matter_10"
)
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p1"
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_particulate_matter_2_5")
assert state
assert state.state == "11"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM25
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get(
"sensor.nettigo_air_monitor_pmsx003_particulate_matter_2_5"
)
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p2"
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_particulate_matter_1_0")
assert state
assert state.state == "6"
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.PM1
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
)
entry = registry.async_get(
"sensor.nettigo_air_monitor_pmsx003_particulate_matter_1_0"
)
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-pms_p0"
state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_10") state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_10")
assert state assert state
assert state.state == "19" assert state.state == "19"
@ -238,18 +305,20 @@ async def test_sensor(hass):
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sds011_caqi") entry = registry.async_get(
"sensor.nettigo_air_monitor_sds011_particulate_matter_10"
)
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_caqi" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p1"
state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi") state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi")
assert state assert state
assert state.state == "19" assert state.state == "19"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_sds011_caqi_level") entry = registry.async_get("sensor.nettigo_air_monitor_sds011_caqi")
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_caqi_level" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_caqi"
state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi_level") state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi_level")
assert state assert state
@ -257,11 +326,9 @@ async def test_sensor(hass):
assert state.attributes.get(ATTR_DEVICE_CLASS) == "nam__caqi_level" assert state.attributes.get(ATTR_DEVICE_CLASS) == "nam__caqi_level"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter" assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = registry.async_get("sensor.nettigo_air_monitor_sds011_caqi_level")
"sensor.nettigo_air_monitor_sds011_particulate_matter_10"
)
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p1" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_caqi_level"
state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_2_5") state = hass.states.get("sensor.nettigo_air_monitor_sds011_particulate_matter_2_5")
assert state assert state
@ -279,6 +346,25 @@ async def test_sensor(hass):
assert entry assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p2" assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sds011_p2"
state = hass.states.get("sensor.nettigo_air_monitor_sps30_caqi")
assert state
assert state.state == "54"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_caqi")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_caqi"
state = hass.states.get("sensor.nettigo_air_monitor_sps30_caqi_level")
assert state
assert state.state == "medium"
assert state.attributes.get(ATTR_DEVICE_CLASS) == "nam__caqi_level"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_caqi_level")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_caqi_level"
state = hass.states.get("sensor.nettigo_air_monitor_sps30_particulate_matter_1_0") state = hass.states.get("sensor.nettigo_air_monitor_sps30_particulate_matter_1_0")
assert state assert state
assert state.state == "31" assert state.state == "31"
@ -289,25 +375,6 @@ async def test_sensor(hass):
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
) )
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_caqi")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_caqi"
state = hass.states.get("sensor.nettigo_air_monitor_sps30_caqi")
assert state
assert state.state == "54"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get("sensor.nettigo_air_monitor_sps30_caqi_level")
assert entry
assert entry.unique_id == "aa:bb:cc:dd:ee:ff-sps30_caqi_level"
state = hass.states.get("sensor.nettigo_air_monitor_sps30_caqi_level")
assert state
assert state.state == "medium"
assert state.attributes.get(ATTR_DEVICE_CLASS) == "nam__caqi_level"
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
entry = registry.async_get( entry = registry.async_get(
"sensor.nettigo_air_monitor_sps30_particulate_matter_1_0" "sensor.nettigo_air_monitor_sps30_particulate_matter_1_0"
) )