diff --git a/homeassistant/components/nam/const.py b/homeassistant/components/nam/const.py index 2b6a74383b5..5e18b94745c 100644 --- a/homeassistant/components/nam/const.py +++ b/homeassistant/components/nam/const.py @@ -22,6 +22,12 @@ ATTR_DHT22_TEMPERATURE: Final = "dht22_temperature" ATTR_HECA_HUMIDITY: Final = "heca_humidity" ATTR_HECA_TEMPERATURE: Final = "heca_temperature" 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_CAQI: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}" ATTR_SDS011_CAQI_LEVEL: Final = f"{ATTR_SDS011}{SUFFIX_CAQI}_level" diff --git a/homeassistant/components/nam/sensor.py b/homeassistant/components/nam/sensor.py index 01107baf31b..ce3fdbf16a8 100644 --- a/homeassistant/components/nam/sensor.py +++ b/homeassistant/components/nam/sensor.py @@ -43,6 +43,11 @@ from .const import ( ATTR_HECA_HUMIDITY, ATTR_HECA_TEMPERATURE, 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_LEVEL, ATTR_SDS011_P1, @@ -136,6 +141,38 @@ SENSORS: tuple[SensorEntityDescription, ...] = ( device_class=SensorDeviceClass.CO2, 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( key=ATTR_SDS011_CAQI, name="SDS011 CAQI", diff --git a/tests/components/nam/test_sensor.py b/tests/components/nam/test_sensor.py index bee4c515cd0..dc9e9a76d76 100644 --- a/tests/components/nam/test_sensor.py +++ b/tests/components/nam/test_sensor.py @@ -228,6 +228,73 @@ async def test_sensor(hass): assert entry 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") assert state assert state.state == "19" @@ -238,18 +305,20 @@ async def test_sensor(hass): == 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.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") assert state assert state.state == "19" 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.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") 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_ICON) == "mdi:air-filter" - entry = registry.async_get( - "sensor.nettigo_air_monitor_sds011_particulate_matter_10" - ) + entry = registry.async_get("sensor.nettigo_air_monitor_sds011_caqi_level") 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") assert state @@ -279,6 +346,25 @@ async def test_sensor(hass): assert entry 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") assert state assert state.state == "31" @@ -289,25 +375,6 @@ async def test_sensor(hass): == 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( "sensor.nettigo_air_monitor_sps30_particulate_matter_1_0" )