From 484d57da5783a849a51190988ef8dc090c685e4d Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:40:12 -0500 Subject: [PATCH] Update test_graphql_value_mapper.py --- tests/test_graphql_value_mapper.py | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/test_graphql_value_mapper.py b/tests/test_graphql_value_mapper.py index 3dac709..cd589e3 100644 --- a/tests/test_graphql_value_mapper.py +++ b/tests/test_graphql_value_mapper.py @@ -3,6 +3,8 @@ import json from pathlib import Path +import pytest + from pyhilo.device.graphql_value_mapper import GraphqlValueMapper PAYLOADS = Path(__file__).parent.parent / "doc" / "graphql" @@ -21,3 +23,74 @@ def test_smart_meter_maps_zigbee_channel() -> None: channel = [a["value"] for a in attributes if a["attribute"] == "ZigbeeChannel"] 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}