Introduce snapshot testing to matter (#126693)

* Introduce snapshot testing to matter

* Introduce snapshot testing to matter
This commit is contained in:
Joost Lekkerkerker 2024-09-25 09:46:32 +02:00 committed by GitHub
parent dff0e2cc9f
commit 31d722f1ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 1636 additions and 272 deletions

View File

@ -70,6 +70,22 @@ async def integration_fixture(
return entry return entry
@pytest.fixture(
params=[
"door-lock",
"smoke-detector",
"air-purifier",
"eve-energy-plug-patched",
"eve-energy-plug",
]
)
async def matter_devices(
hass: HomeAssistant, matter_client: MagicMock, request: pytest.FixtureRequest
) -> MatterNode:
"""Fixture for a Matter device."""
return await setup_integration_with_node_fixture(hass, request.param, matter_client)
@pytest.fixture(name="door_lock") @pytest.fixture(name="door_lock")
async def door_lock_fixture( async def door_lock_fixture(
hass: HomeAssistant, matter_client: MagicMock hass: HomeAssistant, matter_client: MagicMock

View File

@ -0,0 +1,376 @@
# serializer version: 1
# name: test_binary_sensors[door-lock-True][binary_sensor.mock_door_lock_battery-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.mock_door_lock_battery',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.BATTERY: 'battery'>,
'original_icon': None,
'original_name': 'Battery',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-BatteryChargeLevel-47-14',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[door-lock-True][binary_sensor.mock_door_lock_battery-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery',
'friendly_name': 'Mock Door Lock Battery',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.mock_door_lock_battery',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[door-lock-True][binary_sensor.mock_door_lock_door-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.mock_door_lock_door',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
'original_icon': None,
'original_name': 'Door',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-LockDoorStateSensor-257-3',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[door-lock-True][binary_sensor.mock_door_lock_door-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'door',
'friendly_name': 'Mock Door Lock Door',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.mock_door_lock_door',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_battery_alert-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.smoke_sensor_battery_alert',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.BATTERY: 'battery'>,
'original_icon': None,
'original_name': 'Battery alert',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'battery_alert',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmBatteryAlertSensor-92-3',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_battery_alert-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery',
'friendly_name': 'Smoke sensor Battery alert',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_battery_alert',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_end_of_service-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.smoke_sensor_end_of_service',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
'original_icon': None,
'original_name': 'End of service',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'end_of_service',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmEndfOfServiceSensor-92-7',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_end_of_service-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'problem',
'friendly_name': 'Smoke sensor End of service',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_end_of_service',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_hardware_fault-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.smoke_sensor_hardware_fault',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
'original_icon': None,
'original_name': 'Hardware fault',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'hardware_fault',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmHardwareFaultAlertSensor-92-6',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_hardware_fault-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'problem',
'friendly_name': 'Smoke sensor Hardware fault',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_hardware_fault',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_muted-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.smoke_sensor_muted',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Muted',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'muted',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmDeviceMutedSensor-92-4',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_muted-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Smoke sensor Muted',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_muted',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_smoke-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.smoke_sensor_smoke',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.SMOKE: 'smoke'>,
'original_icon': None,
'original_name': 'Smoke',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmSmokeStateSensor-92-1',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_smoke-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'smoke',
'friendly_name': 'Smoke sensor Smoke',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_smoke',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_test_in_progress-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'binary_sensor.smoke_sensor_test_in_progress',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.RUNNING: 'running'>,
'original_icon': None,
'original_name': 'Test in progress',
'platform': 'matter',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'test_in_progress',
'unique_id': '00000000000004D2-0000000000000001-MatterNodeDevice-1-SmokeCoAlarmTestInProgressSensor-92-5',
'unit_of_measurement': None,
})
# ---
# name: test_binary_sensors[smoke-detector-True][binary_sensor.smoke_sensor_test_in_progress-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'running',
'friendly_name': 'Smoke sensor Test in progress',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.smoke_sensor_test_in_progress',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,12 @@ from unittest.mock import MagicMock, patch
from matter_server.client.models.node import MatterNode from matter_server.client.models.node import MatterNode
import pytest import pytest
from syrupy import SnapshotAssertion
from homeassistant.components.matter.binary_sensor import ( from homeassistant.components.matter.binary_sensor import (
DISCOVERY_SCHEMAS as BINARY_SENSOR_SCHEMAS, DISCOVERY_SCHEMAS as BINARY_SENSOR_SCHEMAS,
) )
from homeassistant.const import STATE_OFF, EntityCategory, Platform from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -124,47 +125,21 @@ async def test_battery_sensor(
assert state assert state
assert state.state == "on" assert state.state == "on"
entry = entity_registry.async_get(entity_id)
assert entry
assert entry.entity_category == EntityCategory.DIAGNOSTIC
# This tests needs to be adjusted to remove lingering tasks # This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_smoke_alarm( async def test_binary_sensors(
hass: HomeAssistant, hass: HomeAssistant,
matter_client: MagicMock, matter_client: MagicMock,
smoke_detector: MatterNode, matter_devices: MatterNode,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test smoke detector.""" """Test binary sensors."""
entities = hass.states.async_all(Platform.BINARY_SENSOR)
# Muted for entity_state in entities:
state = hass.states.get("binary_sensor.smoke_sensor_muted") entity_entry = entity_registry.async_get(entity_state.entity_id)
assert state assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
assert state.state == STATE_OFF state = hass.states.get(entity_entry.entity_id)
assert state, f"State not found for {entity_entry.entity_id}"
# End of service assert state == snapshot(name=f"{entity_entry.entity_id}-state")
state = hass.states.get("binary_sensor.smoke_sensor_end_of_service")
assert state
assert state.state == STATE_OFF
# Battery alert
state = hass.states.get("binary_sensor.smoke_sensor_battery_alert")
assert state
assert state.state == STATE_OFF
# Test in progress
state = hass.states.get("binary_sensor.smoke_sensor_test_in_progress")
assert state
assert state.state == STATE_OFF
# Hardware fault
state = hass.states.get("binary_sensor.smoke_sensor_hardware_fault")
assert state
assert state.state == STATE_OFF
# Smoke
state = hass.states.get("binary_sensor.smoke_sensor_smoke")
assert state
assert state.state == STATE_OFF

View File

@ -4,8 +4,9 @@ from unittest.mock import MagicMock
from matter_server.client.models.node import MatterNode from matter_server.client.models.node import MatterNode
import pytest import pytest
from syrupy import SnapshotAssertion
from homeassistant.const import EntityCategory from homeassistant.const import EntityCategory, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
@ -286,112 +287,6 @@ async def test_battery_sensor_voltage(
assert entry.entity_category == EntityCategory.DIAGNOSTIC assert entry.entity_category == EntityCategory.DIAGNOSTIC
# This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_energy_sensors_custom_cluster(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
matter_client: MagicMock,
eve_energy_plug_node: MatterNode,
) -> None:
"""Test Energy sensors created from (Eve) custom cluster (Matter 1.3 energy clusters absent)."""
# power sensor on Eve custom cluster
entity_id = "sensor.eve_energy_plug_power"
state = hass.states.get(entity_id)
assert state
assert state.state == "0.0"
assert state.attributes["unit_of_measurement"] == "W"
assert state.attributes["device_class"] == "power"
assert state.attributes["friendly_name"] == "Eve Energy Plug Power"
# voltage sensor on Eve custom cluster
entity_id = "sensor.eve_energy_plug_voltage"
state = hass.states.get(entity_id)
assert state
assert state.state == "238.800003051758"
assert state.attributes["unit_of_measurement"] == "V"
assert state.attributes["device_class"] == "voltage"
assert state.attributes["friendly_name"] == "Eve Energy Plug Voltage"
# energy sensor on Eve custom cluster
entity_id = "sensor.eve_energy_plug_energy"
state = hass.states.get(entity_id)
assert state
assert state.state == "0.220000028610229"
assert state.attributes["unit_of_measurement"] == "kWh"
assert state.attributes["device_class"] == "energy"
assert state.attributes["friendly_name"] == "Eve Energy Plug Energy"
assert state.attributes["state_class"] == "total_increasing"
# current sensor on Eve custom cluster
entity_id = "sensor.eve_energy_plug_current"
state = hass.states.get(entity_id)
assert state
assert state.state == "0.0"
assert state.attributes["unit_of_measurement"] == "A"
assert state.attributes["device_class"] == "current"
assert state.attributes["friendly_name"] == "Eve Energy Plug Current"
# This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_energy_sensors(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
matter_client: MagicMock,
eve_energy_plug_patched_node: MatterNode,
) -> None:
"""Test Energy sensors created from official Matter 1.3 energy clusters."""
# power sensor on Matter 1.3 ElectricalPowermeasurement cluster
entity_id = "sensor.eve_energy_plug_patched_power"
state = hass.states.get(entity_id)
assert state
assert state.state == "550.0"
assert state.attributes["unit_of_measurement"] == "W"
assert state.attributes["device_class"] == "power"
assert state.attributes["friendly_name"] == "Eve Energy Plug Patched Power"
# ensure we do not have a duplicated entity from the custom cluster
state = hass.states.get(f"{entity_id}_1")
assert state is None
# voltage sensor on Matter 1.3 ElectricalPowermeasurement cluster
entity_id = "sensor.eve_energy_plug_patched_voltage"
state = hass.states.get(entity_id)
assert state
assert state.state == "220.0"
assert state.attributes["unit_of_measurement"] == "V"
assert state.attributes["device_class"] == "voltage"
assert state.attributes["friendly_name"] == "Eve Energy Plug Patched Voltage"
# ensure we do not have a duplicated entity from the custom cluster
state = hass.states.get(f"{entity_id}_1")
assert state is None
# energy sensor on Matter 1.3 ElectricalEnergymeasurement cluster
entity_id = "sensor.eve_energy_plug_patched_energy"
state = hass.states.get(entity_id)
assert state
assert state.state == "0.0025"
assert state.attributes["unit_of_measurement"] == "kWh"
assert state.attributes["device_class"] == "energy"
assert state.attributes["friendly_name"] == "Eve Energy Plug Patched Energy"
assert state.attributes["state_class"] == "total_increasing"
# ensure we do not have a duplicated entity from the custom cluster
state = hass.states.get(f"{entity_id}_1")
assert state is None
# current sensor on Matter 1.3 ElectricalPowermeasurement cluster
entity_id = "sensor.eve_energy_plug_patched_current"
state = hass.states.get(entity_id)
assert state
assert state.state == "2.0"
assert state.attributes["unit_of_measurement"] == "A"
assert state.attributes["device_class"] == "current"
assert state.attributes["friendly_name"] == "Eve Energy Plug Patched Current"
# ensure we do not have a duplicated entity from the custom cluster
state = hass.states.get(f"{entity_id}_1")
assert state is None
# This tests needs to be adjusted to remove lingering tasks # This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True]) @pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_eve_thermo_sensor( async def test_eve_thermo_sensor(
@ -508,132 +403,6 @@ async def test_air_quality_sensor(
assert state.state == "50.0" 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"
# Air Quality
state = hass.states.get("sensor.air_purifier_air_quality")
assert state
assert state.state == "good"
expected_options = [
"extremely_poor",
"very_poor",
"poor",
"fair",
"good",
"moderate",
]
assert set(state.attributes["options"]) == set(expected_options)
assert state.attributes["device_class"] == "enum"
assert state.attributes["friendly_name"] == "Air Purifier Air quality"
# Carbon MonoOxide
state = hass.states.get("sensor.air_purifier_carbon_monoxide")
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"] == "carbon_monoxide"
assert state.attributes["friendly_name"] == "Air Purifier Carbon monoxide"
# Nitrogen Dioxide
state = hass.states.get("sensor.air_purifier_nitrogen_dioxide")
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"] == "nitrogen_dioxide"
assert state.attributes["friendly_name"] == "Air Purifier Nitrogen dioxide"
# Ozone Concentration
state = hass.states.get("sensor.air_purifier_ozone")
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"] == "ozone"
assert state.attributes["friendly_name"] == "Air Purifier Ozone"
# Hepa Filter Condition
state = hass.states.get("sensor.air_purifier_hepa_filter_condition")
assert state
assert state.state == "100"
assert state.attributes["state_class"] == "measurement"
assert state.attributes["unit_of_measurement"] == "%"
assert state.attributes["friendly_name"] == "Air Purifier Hepa filter condition"
# Activated Carbon Filter Condition
state = hass.states.get("sensor.air_purifier_activated_carbon_filter_condition")
assert state
assert state.state == "100"
assert state.attributes["state_class"] == "measurement"
assert state.attributes["unit_of_measurement"] == "%"
# This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_smoke_alarm(
hass: HomeAssistant,
matter_client: MagicMock,
smoke_detector: MatterNode,
) -> None:
"""Test smoke detector."""
# Battery
state = hass.states.get("sensor.smoke_sensor_battery")
assert state
assert state.state == "94"
# Voltage
state = hass.states.get("sensor.smoke_sensor_voltage")
assert state
assert state.state == "0.0"
async def test_operational_state_sensor( async def test_operational_state_sensor(
hass: HomeAssistant, hass: HomeAssistant,
matter_client: MagicMock, matter_client: MagicMock,
@ -658,3 +427,22 @@ async def test_operational_state_sensor(
state = hass.states.get("sensor.dishwasher_operational_state") state = hass.states.get("sensor.dishwasher_operational_state")
assert state assert state
assert state.state == "extra_state" assert state.state == "extra_state"
# This tests needs to be adjusted to remove lingering tasks
@pytest.mark.parametrize("expected_lingering_tasks", [True])
async def test_sensors(
hass: HomeAssistant,
matter_client: MagicMock,
matter_devices: MatterNode,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test sensors."""
entities = hass.states.async_all(Platform.SENSOR)
for entity_state in entities:
entity_entry = entity_registry.async_get(entity_state.entity_id)
assert entity_entry == snapshot(name=f"{entity_entry.entity_id}-entry")
state = hass.states.get(entity_entry.entity_id)
assert state, f"State not found for {entity_entry.entity_id}"
assert state == snapshot(name=f"{entity_entry.entity_id}-state")