Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Total Volatile Organic Compounds (tVOC) matter discovery schema #116963

Merged
merged 3 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions homeassistant/components/matter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
58 changes: 58 additions & 0 deletions tests/components/matter/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"