mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Add test for combining state change and state report listeners (#148721)
This commit is contained in:
parent
254f766357
commit
1a1e9e9f57
@ -4946,6 +4946,37 @@ async def test_async_track_state_report_event(hass: HomeAssistant) -> None:
|
||||
unsub()
|
||||
|
||||
|
||||
async def test_async_track_state_report_change_event(hass: HomeAssistant) -> None:
|
||||
"""Test listen for both state change and state report events."""
|
||||
tracker_called: dict[str, list[str]] = {"light.bowl": [], "light.top": []}
|
||||
|
||||
@ha.callback
|
||||
def on_state_change(event: Event[EventStateChangedData]) -> None:
|
||||
new_state = event.data["new_state"].state
|
||||
tracker_called[event.data["entity_id"]].append(new_state)
|
||||
|
||||
@ha.callback
|
||||
def on_state_report(event: Event[EventStateReportedData]) -> None:
|
||||
new_state = event.data["new_state"].state
|
||||
tracker_called[event.data["entity_id"]].append(new_state)
|
||||
|
||||
async_track_state_change_event(hass, ["light.bowl", "light.top"], on_state_change)
|
||||
async_track_state_report_event(hass, ["light.bowl", "light.top"], on_state_report)
|
||||
entity_ids = ["light.bowl", "light.top"]
|
||||
state_sequence = ["on", "on", "off", "off"]
|
||||
for state in state_sequence:
|
||||
for entity_id in entity_ids:
|
||||
hass.states.async_set(entity_id, state)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# The out-of-order is a result of state change listeners scheduled with
|
||||
# loop.call_soon, whereas state report listeners are called immediately.
|
||||
assert tracker_called == {
|
||||
"light.bowl": ["on", "off", "on", "off"],
|
||||
"light.top": ["on", "off", "on", "off"],
|
||||
}
|
||||
|
||||
|
||||
async def test_async_track_template_no_hass_deprecated(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user