Skip to content

Commit c17206f

Browse files
committed
Add testing
1 parent 9836466 commit c17206f

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_events.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import pytest
44

5+
from homeassistant_api.models import (
6+
ConfigEntryChange,
7+
ConfigEntryDisabler,
8+
ConfigEntryState,
9+
)
510
from homeassistant_api.websocket import WebsocketClient
611

712

@@ -28,3 +33,40 @@ def test_listen_trigger(websocket_client: WebsocketClient) -> None:
2833
assert datetime.fromisoformat(
2934
trigger["trigger"]["now"]
3035
).timestamp() == pytest.approx(future.timestamp(), abs=1)
36+
37+
38+
def test_listen_config_entries(websocket_client: WebsocketClient) -> None:
39+
with websocket_client.listen_config_entries() as flows:
40+
for i, flow in zip(range(5), flows):
41+
# The first "events" are currently available entries
42+
if i == 0:
43+
# Assumes that the first entry (sun.sun?) is enabled
44+
assert flow[0].type is None
45+
assert flow[0].entry.disabled_by is None
46+
assert flow[0].entry.state == ConfigEntryState.LOADED
47+
48+
# Trigger an "updated" event
49+
websocket_client.disable_config_entry(flow[0].entry.entry_id)
50+
51+
if i == 1:
52+
assert flow[0].type == ConfigEntryChange.UPDATED
53+
assert flow[0].entry.disabled_by == ConfigEntryDisabler.USER
54+
assert flow[0].entry.state == ConfigEntryState.UNLOAD_IN_PROGRESS
55+
56+
if i == 2:
57+
assert flow[0].type == ConfigEntryChange.UPDATED
58+
assert flow[0].entry.disabled_by == ConfigEntryDisabler.USER
59+
assert flow[0].entry.state == ConfigEntryState.NOT_LOADED
60+
61+
# Restore original state
62+
websocket_client.enable_config_entry(flow[0].entry.entry_id)
63+
64+
if i == 3:
65+
assert flow[0].type == ConfigEntryChange.UPDATED
66+
assert flow[0].entry.disabled_by is None
67+
assert flow[0].entry.state == ConfigEntryState.SETUP_IN_PROGRESS
68+
69+
if i == 4:
70+
assert flow[0].type == ConfigEntryChange.UPDATED
71+
assert flow[0].entry.disabled_by is None
72+
assert flow[0].entry.state == ConfigEntryState.LOADED

0 commit comments

Comments
 (0)