From b41b56e54c3ae0a06e42b7c370f0dbbd625c15f6 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Fri, 24 Nov 2023 11:39:13 +0100 Subject: [PATCH] Support new deCONZ Particulate Matter endpoint (#104276) --- homeassistant/components/deconz/manifest.json | 2 +- homeassistant/components/deconz/sensor.py | 13 +++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/deconz/test_sensor.py | 49 +++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/deconz/manifest.json b/homeassistant/components/deconz/manifest.json index 6245558a1c5..af1824e441c 100644 --- a/homeassistant/components/deconz/manifest.json +++ b/homeassistant/components/deconz/manifest.json @@ -8,7 +8,7 @@ "iot_class": "local_push", "loggers": ["pydeconz"], "quality_scale": "platinum", - "requirements": ["pydeconz==113"], + "requirements": ["pydeconz==114"], "ssdp": [ { "manufacturer": "Royal Philips Electronics", diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index a635a784676..ecb9ac9b297 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -17,6 +17,7 @@ from pydeconz.models.sensor.generic_status import GenericStatus from pydeconz.models.sensor.humidity import Humidity from pydeconz.models.sensor.light_level import LightLevel from pydeconz.models.sensor.moisture import Moisture +from pydeconz.models.sensor.particulate_matter import ParticulateMatter from pydeconz.models.sensor.power import Power from pydeconz.models.sensor.pressure import Pressure from pydeconz.models.sensor.switch import Switch @@ -83,6 +84,7 @@ T = TypeVar( Humidity, LightLevel, Moisture, + ParticulateMatter, Power, Pressure, Temperature, @@ -213,6 +215,17 @@ ENTITY_DESCRIPTIONS: tuple[DeconzSensorDescription, ...] = ( native_unit_of_measurement=PERCENTAGE, suggested_display_precision=1, ), + DeconzSensorDescription[ParticulateMatter]( + key="particulate_matter_pm2_5", + supported_fn=lambda device: device.measured_value is not None, + update_key="measured_value", + value_fn=lambda device: device.measured_value, + instance_check=ParticulateMatter, + name_suffix="PM25", + device_class=SensorDeviceClass.PM25, + state_class=SensorStateClass.MEASUREMENT, + native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + ), DeconzSensorDescription[Power]( key="power", supported_fn=lambda device: device.power is not None, diff --git a/requirements_all.txt b/requirements_all.txt index fd0c3225958..d35ee88e994 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1680,7 +1680,7 @@ pydaikin==2.11.1 pydanfossair==0.1.0 # homeassistant.components.deconz -pydeconz==113 +pydeconz==114 # homeassistant.components.delijn pydelijn==1.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f440046b5a6..2ad933fa42c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1272,7 +1272,7 @@ pycsspeechtts==1.0.8 pydaikin==2.11.1 # homeassistant.components.deconz -pydeconz==113 +pydeconz==114 # homeassistant.components.dexcom pydexcom==0.2.3 diff --git a/tests/components/deconz/test_sensor.py b/tests/components/deconz/test_sensor.py index 7fa93266aef..38d68d135b6 100644 --- a/tests/components/deconz/test_sensor.py +++ b/tests/components/deconz/test_sensor.py @@ -530,6 +530,55 @@ TEST_DATA = [ "next_state": "1.3", }, ), + ( # Particulate matter -> pm2_5 + { + "capabilities": { + "measured_value": { + "max": 999, + "min": 0, + "quantity": "density", + "substance": "PM2.5", + "unit": "ug/m^3", + } + }, + "config": {"on": True, "reachable": True}, + "ep": 1, + "etag": "2a67a4b5cbcc20532c0ee75e2abac0c3", + "lastannounced": None, + "lastseen": "2023-10-29T12:59Z", + "manufacturername": "IKEA of Sweden", + "modelid": "STARKVIND Air purifier table", + "name": "STARKVIND AirPurifier", + "productid": "E2006", + "state": { + "airquality": "excellent", + "lastupdated": "2023-10-29T12:59:27.976", + "measured_value": 1, + "pm2_5": 1, + }, + "swversion": "1.1.001", + "type": "ZHAParticulateMatter", + "uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-042a", + }, + { + "entity_count": 1, + "device_count": 3, + "entity_id": "sensor.starkvind_airpurifier_pm25", + "unique_id": "xx:xx:xx:xx:xx:xx:xx:xx-01-042a-particulate_matter_pm2_5", + "state": "1", + "entity_category": None, + "device_class": SensorDeviceClass.PM25, + "state_class": SensorStateClass.MEASUREMENT, + "attributes": { + "friendly_name": "STARKVIND AirPurifier PM25", + "device_class": SensorDeviceClass.PM25, + "state_class": SensorStateClass.MEASUREMENT, + "unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + }, + "websocket_event": {"state": {"measured_value": 2}}, + "next_state": "2", + }, + ), ( # Power sensor { "config": {