From e08a94fe1c938d0845733194d910f8d2cde42426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Mon, 16 Sep 2024 14:16:03 +0200 Subject: [PATCH] Add Matter tests for BatVoltage attribute from PowerSource cluster (#125645) * Add BatVoltage Attribute from PowerSource Cluster * Update sensor.py Remove comment * Update homeassistant/components/matter/sensor.py Co-authored-by: Martin Hjelmare * Fixture for a Eve Door & Window node Fixture for a Eve Door & Window node to check BatVoltage attribute from PowerSource cluster * Test battery voltage sensor * Update test_sensor.py * ruff-format * Update test_sensor.py * Update test_sensor.py battery_voltage attribute test * Update test_sensor.py * Update test_sensor.py * Update tests/components/matter/test_sensor.py Co-authored-by: Martin Hjelmare * Update test_sensor.py * Adjust values --------- Co-authored-by: Martin Hjelmare --- tests/components/matter/test_sensor.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/components/matter/test_sensor.py b/tests/components/matter/test_sensor.py index 17cff38787c..20ecef8609b 100644 --- a/tests/components/matter/test_sensor.py +++ b/tests/components/matter/test_sensor.py @@ -251,6 +251,33 @@ async def test_battery_sensor( 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_battery_sensor_voltage( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + matter_client: MagicMock, + eve_contact_sensor_node: MatterNode, +) -> None: + """Test battery voltage sensor.""" + entity_id = "sensor.eve_door_voltage" + state = hass.states.get(entity_id) + assert state + assert state.state == "3.558" + + set_node_attribute(eve_contact_sensor_node, 1, 47, 11, 4234) + await trigger_subscription_callback(hass, matter_client) + + state = hass.states.get(entity_id) + assert state + assert state.state == "4.234" + + 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 @pytest.mark.parametrize("expected_lingering_tasks", [True]) async def test_energy_sensors_custom_cluster(