Skip to content

Commit aa4151c

Browse files
kylewhirlmarcelveldtjoostlek
authored
Fix for Hue Integration motion aware areas (home-assistant#153079)
Co-authored-by: Marcel van der Veldt <[email protected]> Co-authored-by: Joost Lekkerkerker <[email protected]>
1 parent 0a6fa97 commit aa4151c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

homeassistant/components/hue/v2/binary_sensor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ def is_on(self) -> bool | None:
145145
if not self.resource.enabled:
146146
# Force None (unknown) if the sensor is set to disabled in Hue
147147
return None
148-
return self.resource.motion.value
148+
if not (motion_feature := self.resource.motion):
149+
return None
150+
if motion_feature.motion_report is not None:
151+
return motion_feature.motion_report.motion
152+
return motion_feature.motion
149153

150154

151155
# pylint: disable-next=hass-enforce-class-module

tests/components/hue/test_binary_sensor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ async def test_binary_sensor_add_update(
123123
test_entity = hass.states.get(test_entity_id)
124124
assert test_entity is not None
125125
assert test_entity.state == "on"
126+
# NEW: prefer motion_report.motion when present (should turn on even if plain motion is False)
127+
updated_sensor = {
128+
**FAKE_BINARY_SENSOR,
129+
"motion": {
130+
"motion": False,
131+
"motion_report": {"changed": "2025-01-01T00:00:00Z", "motion": True},
132+
},
133+
}
134+
mock_bridge_v2.api.emit_event("update", updated_sensor)
135+
await hass.async_block_till_done()
136+
assert hass.states.get(test_entity_id).state == "on"
137+
138+
# NEW: motion_report False should turn it off (even if plain motion is True)
139+
updated_sensor = {
140+
**FAKE_BINARY_SENSOR,
141+
"motion": {
142+
"motion": True,
143+
"motion_report": {"changed": "2025-01-01T00:00:01Z", "motion": False},
144+
},
145+
}
146+
mock_bridge_v2.api.emit_event("update", updated_sensor)
147+
await hass.async_block_till_done()
148+
assert hass.states.get(test_entity_id).state == "off"
126149

127150

128151
async def test_grouped_motion_sensor(

0 commit comments

Comments
 (0)