Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tests/test_graphql_value_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,77 @@ def test_smart_meter_maps_zigbee_channel() -> None:
assert channel == [24]


def _hub(connection_status: str) -> dict:
return {
"hiloId": "hub-1",
"deviceType": "Hub",
"connectionStatus": connection_status,
"lastConnectionTime": "2026-11-01T12:00:00Z",
"controllerSoftwareVersion": "1.0.0",
"zigBeePairingModeEnhanced": False,
"willBeConnectedToSmartMeter": False,
"smartMeterPairingStatus": False,
}


def _disconnected_values(device: dict) -> set[bool]:
attributes = GraphqlValueMapper().map_device_subscription_values(device)
return {a["value"] for a in attributes if a["attribute"] == "Disconnected"}


@pytest.mark.parametrize(
("filename", "connection_status", "expected"),
[
pytest.param(
"onAnyDeviceUpdated-tstat.json", "CONNECTED", False, id="tstat-connected"
),
pytest.param(
"onAnyDeviceUpdated-tstat.json",
"DISCONNECTED",
True,
id="tstat-disconnected",
),
pytest.param(
"onAnyDeviceUpdated-cee.json", "CONNECTED", False, id="cee-connected"
),
pytest.param(
"onAnyDeviceUpdated-cee.json", "DISCONNECTED", True, id="cee-disconnected"
),
pytest.param(
"onAnyDeviceUpdated-meter.json", "CONNECTED", False, id="meter-connected"
),
pytest.param(
"onAnyDeviceUpdated-meter.json",
"DISCONNECTED",
True,
id="meter-disconnected",
),
],
)
def test_device_disconnected_follows_connection_status(
filename: str, connection_status: str, expected: bool
) -> None:
"""Hilo reports connectionStatus as a string; DISCONNECTED maps to Disconnected=True."""
device = _device(filename)
device["connectionStatus"] = connection_status

assert _disconnected_values(device) == {expected}


@pytest.mark.parametrize(
("connection_status", "expected"),
[
pytest.param("CONNECTED", False, id="connected"),
pytest.param("DISCONNECTED", True, id="disconnected"),
],
)
def test_hub_disconnected_follows_connection_status(
connection_status: str, expected: bool
) -> None:
"""The gateway's Disconnected attribute is derived from the string status."""
assert _disconnected_values(_hub(connection_status)) == {expected}


@pytest.mark.parametrize(
("ambient_humidity", "expected"),
[
Expand Down
Loading