Skip to content

Commit d038f28

Browse files
authored
Merge pull request #490 from dvd-dev/bugfix/disconnected-attribute
Update test_graphql_value_mapper.py
2 parents 71e24b7 + 79fdbf5 commit d038f28

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

‎tests/test_graphql_value_mapper.py‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,77 @@ def test_smart_meter_maps_zigbee_channel() -> None:
2525
assert channel == [24]
2626

2727

28+
def _hub(connection_status: str) -> dict:
29+
return {
30+
"hiloId": "hub-1",
31+
"deviceType": "Hub",
32+
"connectionStatus": connection_status,
33+
"lastConnectionTime": "2026-11-01T12:00:00Z",
34+
"controllerSoftwareVersion": "1.0.0",
35+
"zigBeePairingModeEnhanced": False,
36+
"willBeConnectedToSmartMeter": False,
37+
"smartMeterPairingStatus": False,
38+
}
39+
40+
41+
def _disconnected_values(device: dict) -> set[bool]:
42+
attributes = GraphqlValueMapper().map_device_subscription_values(device)
43+
return {a["value"] for a in attributes if a["attribute"] == "Disconnected"}
44+
45+
46+
@pytest.mark.parametrize(
47+
("filename", "connection_status", "expected"),
48+
[
49+
pytest.param(
50+
"onAnyDeviceUpdated-tstat.json", "CONNECTED", False, id="tstat-connected"
51+
),
52+
pytest.param(
53+
"onAnyDeviceUpdated-tstat.json",
54+
"DISCONNECTED",
55+
True,
56+
id="tstat-disconnected",
57+
),
58+
pytest.param(
59+
"onAnyDeviceUpdated-cee.json", "CONNECTED", False, id="cee-connected"
60+
),
61+
pytest.param(
62+
"onAnyDeviceUpdated-cee.json", "DISCONNECTED", True, id="cee-disconnected"
63+
),
64+
pytest.param(
65+
"onAnyDeviceUpdated-meter.json", "CONNECTED", False, id="meter-connected"
66+
),
67+
pytest.param(
68+
"onAnyDeviceUpdated-meter.json",
69+
"DISCONNECTED",
70+
True,
71+
id="meter-disconnected",
72+
),
73+
],
74+
)
75+
def test_device_disconnected_follows_connection_status(
76+
filename: str, connection_status: str, expected: bool
77+
) -> None:
78+
"""Hilo reports connectionStatus as a string; DISCONNECTED maps to Disconnected=True."""
79+
device = _device(filename)
80+
device["connectionStatus"] = connection_status
81+
82+
assert _disconnected_values(device) == {expected}
83+
84+
85+
@pytest.mark.parametrize(
86+
("connection_status", "expected"),
87+
[
88+
pytest.param("CONNECTED", False, id="connected"),
89+
pytest.param("DISCONNECTED", True, id="disconnected"),
90+
],
91+
)
92+
def test_hub_disconnected_follows_connection_status(
93+
connection_status: str, expected: bool
94+
) -> None:
95+
"""The gateway's Disconnected attribute is derived from the string status."""
96+
assert _disconnected_values(_hub(connection_status)) == {expected}
97+
98+
2899
@pytest.mark.parametrize(
29100
("ambient_humidity", "expected"),
30101
[

0 commit comments

Comments
 (0)