From 80bbe5df6aba7fdedefe58d3b06e458d5d5110c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Mon, 9 Feb 2026 19:36:34 +0100 Subject: [PATCH] Add smoke detector test to Matter binary sensor tests (#162638) --- tests/components/matter/test_binary_sensor.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/components/matter/test_binary_sensor.py b/tests/components/matter/test_binary_sensor.py index 146a9f6f824..972728e7f4a 100644 --- a/tests/components/matter/test_binary_sensor.py +++ b/tests/components/matter/test_binary_sensor.py @@ -596,3 +596,60 @@ async def test_thermostat_remote_sensing( state = hass.states.get("binary_sensor.mock_thermostat_occupancy_remote_sensing") assert state assert state.state == "on" + + +@pytest.mark.parametrize("node_fixture", ["heiman_smoke_detector"]) +async def test_smoke_detector( + hass: HomeAssistant, + matter_client: MagicMock, + matter_node: MatterNode, +) -> None: + """Test smoke detector sensor.""" + smoke_state_attribute = clusters.SmokeCoAlarm.Attributes.SmokeState + + # Test initial state (SmokeState = 0, kNormal) + state = hass.states.get("binary_sensor.smoke_sensor_smoke") + assert state + assert state.state == "off" + + # Set SmokeState to kWarning (value 1) + set_node_attribute( + matter_node, + 1, + smoke_state_attribute.cluster_id, + smoke_state_attribute.attribute_id, + 1, + ) + await trigger_subscription_callback(hass, matter_client) + + state = hass.states.get("binary_sensor.smoke_sensor_smoke") + assert state + assert state.state == "on" + + # Set SmokeState to kCritical (value 2) + set_node_attribute( + matter_node, + 1, + smoke_state_attribute.cluster_id, + smoke_state_attribute.attribute_id, + 2, + ) + await trigger_subscription_callback(hass, matter_client) + + state = hass.states.get("binary_sensor.smoke_sensor_smoke") + assert state + assert state.state == "on" + + # Set SmokeState back to kNormal (value 0) + set_node_attribute( + matter_node, + 1, + smoke_state_attribute.cluster_id, + smoke_state_attribute.attribute_id, + 0, + ) + await trigger_subscription_callback(hass, matter_client) + + state = hass.states.get("binary_sensor.smoke_sensor_smoke") + assert state + assert state.state == "off"