Revert to using call_soon for event triggers and state changed event trackers (#122735)
This commit is contained in:
parent
869ec3f670
commit
1879db9f8f
9 changed files with 233 additions and 6 deletions
|
@ -24,6 +24,7 @@ from homeassistant.core import Context, HomeAssistant, State, SupportsResponse,
|
|||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.loader import async_get_integration
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.json import json_loads
|
||||
|
@ -2814,3 +2815,54 @@ async def test_integration_descriptions(
|
|||
|
||||
assert response["success"]
|
||||
assert response["result"]
|
||||
|
||||
|
||||
async def test_subscribe_entities_chained_state_change(
|
||||
hass: HomeAssistant,
|
||||
websocket_client: MockHAClientWebSocket,
|
||||
hass_admin_user: MockUser,
|
||||
) -> None:
|
||||
"""Test chaining state changed events.
|
||||
|
||||
Ensure the websocket sends the off state after
|
||||
the on state.
|
||||
"""
|
||||
|
||||
@callback
|
||||
def auto_off_listener(event):
|
||||
hass.states.async_set("light.permitted", "off")
|
||||
|
||||
async_track_state_change_event(hass, ["light.permitted"], auto_off_listener)
|
||||
|
||||
await websocket_client.send_json({"id": 7, "type": "subscribe_entities"})
|
||||
|
||||
data = await websocket_client.receive_str()
|
||||
msg = json_loads(data)
|
||||
assert msg["id"] == 7
|
||||
assert msg["type"] == const.TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
data = await websocket_client.receive_str()
|
||||
msg = json_loads(data)
|
||||
assert msg["id"] == 7
|
||||
assert msg["type"] == "event"
|
||||
assert msg["event"] == {"a": {}}
|
||||
|
||||
hass.states.async_set("light.permitted", "on")
|
||||
data = await websocket_client.receive_str()
|
||||
msg = json_loads(data)
|
||||
assert msg["id"] == 7
|
||||
assert msg["type"] == "event"
|
||||
assert msg["event"] == {
|
||||
"a": {"light.permitted": {"a": {}, "c": ANY, "lc": ANY, "s": "on"}}
|
||||
}
|
||||
data = await websocket_client.receive_str()
|
||||
msg = json_loads(data)
|
||||
assert msg["id"] == 7
|
||||
assert msg["type"] == "event"
|
||||
assert msg["event"] == {
|
||||
"c": {"light.permitted": {"+": {"c": ANY, "lc": ANY, "s": "off"}}}
|
||||
}
|
||||
|
||||
await websocket_client.close()
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue