diff --git a/homeassistant/components/matter/sensor.py b/homeassistant/components/matter/sensor.py index ff5848ef54e329..4e2644a1ff7ecd 100644 --- a/homeassistant/components/matter/sensor.py +++ b/homeassistant/components/matter/sensor.py @@ -219,6 +219,19 @@ def _update_from_device(self) -> None: clusters.CarbonDioxideConcentrationMeasurement.Attributes.MeasuredValue, ), ), + MatterDiscoverySchema( + platform=Platform.SENSOR, + entity_description=MatterSensorEntityDescription( + key="TotalVolatileOrganicCompoundsSensor", + native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION, + device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS, + state_class=SensorStateClass.MEASUREMENT, + ), + entity_class=MatterSensor, + required_attributes=( + clusters.TotalVolatileOrganicCompoundsConcentrationMeasurement.Attributes.MeasuredValue, + ), + ), MatterDiscoverySchema( platform=Platform.SENSOR, entity_description=MatterSensorEntityDescription( diff --git a/tests/components/matter/test_sensor.py b/tests/components/matter/test_sensor.py index 4ee6180ad772b9..42b13e24c9e7d3 100644 --- a/tests/components/matter/test_sensor.py +++ b/tests/components/matter/test_sensor.py @@ -84,6 +84,16 @@ async def air_quality_sensor_node_fixture( ) +@pytest.fixture(name="air_purifier_node") +async def air_purifier_node_fixture( + hass: HomeAssistant, matter_client: MagicMock +) -> MatterNode: + """Fixture for an air purifier node.""" + return await setup_integration_with_node_fixture( + hass, "air-purifier", matter_client + ) + + # This tests needs to be adjusted to remove lingering tasks @pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_sensor_null_value( @@ -333,3 +343,51 @@ async def test_air_quality_sensor( state = hass.states.get("sensor.lightfi_aq1_air_quality_sensor_pm10") assert state assert state.state == "50.0" + + +# This tests needs to be adjusted to remove lingering tasks +@pytest.mark.parametrize("expected_lingering_tasks", [True]) +async def test_air_purifier_sensor( + hass: HomeAssistant, + matter_client: MagicMock, + air_purifier_node: MatterNode, +) -> None: + """Test Air quality sensors are creayted for air purifier device.""" + # Carbon Dioxide + state = hass.states.get("sensor.air_purifier_carbon_dioxide") + assert state + assert state.state == "2.0" + + # PM1 + state = hass.states.get("sensor.air_purifier_pm1") + assert state + assert state.state == "2.0" + + # PM2.5 + state = hass.states.get("sensor.air_purifier_pm2_5") + assert state + assert state.state == "2.0" + + # PM10 + state = hass.states.get("sensor.air_purifier_pm10") + assert state + assert state.state == "2.0" + + # Temperature + state = hass.states.get("sensor.air_purifier_temperature") + assert state + assert state.state == "20.0" + + # Humidity + state = hass.states.get("sensor.air_purifier_humidity") + assert state + assert state.state == "50.0" + + # VOCS + state = hass.states.get("sensor.air_purifier_vocs") + assert state + assert state.state == "2.0" + assert state.attributes["state_class"] == "measurement" + assert state.attributes["unit_of_measurement"] == "ppm" + assert state.attributes["device_class"] == "volatile_organic_compounds_parts" + assert state.attributes["friendly_name"] == "Air Purifier VOCs"