From 3ea510be7869af4413faf5a7182f623d7b973b85 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:59:24 -0400 Subject: [PATCH 1/3] Add graphql mapper unit test --- tests/test_graphql_value_mapper.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/test_graphql_value_mapper.py diff --git a/tests/test_graphql_value_mapper.py b/tests/test_graphql_value_mapper.py new file mode 100644 index 0000000..245dce2 --- /dev/null +++ b/tests/test_graphql_value_mapper.py @@ -0,0 +1,23 @@ +"""Tests for mapping GraphQL subscription payloads to device attributes.""" + +import json +from pathlib import Path + +from pyhilo.device.graphql_value_mapper import GraphqlValueMapper + +PAYLOADS = Path(__file__).parent.parent / "doc" / "graphql" + + +def _device(filename: str) -> dict: + payload = json.loads((PAYLOADS / filename).read_text(encoding="utf-8")) + return payload["data"]["onAnyDeviceUpdated"]["device"] + + +def test_smart_meter_maps_zigbee_channel() -> None: + """The meter's Zigbee channel is reported as the ZigbeeChannel attribute.""" + attributes = GraphqlValueMapper().map_device_subscription_values( + _device("onAnyDeviceUpdated-meter.json") + ) + + channel = [a["value"] for a in attributes if a["attribute"] == "ZigbeeChannel"] + assert channel == [24] \ No newline at end of file From 8937ccf5b42de1ad0a8cc689a459afee611a59a8 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 25 Oct 2026 17:04:27 -0400 Subject: [PATCH 2/3] =?UTF-8?q?R=C3=A9gler=20le=20typo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hilo nous retourne zigBeeChannel, petit typo. --- pyhilo/device/graphql_value_mapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyhilo/device/graphql_value_mapper.py b/pyhilo/device/graphql_value_mapper.py index ac5765c..5399a44 100644 --- a/pyhilo/device/graphql_value_mapper.py +++ b/pyhilo/device/graphql_value_mapper.py @@ -76,7 +76,7 @@ def _map_to_device_reading( def _build_smart_meter(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: attributes = [] - if device.get("zigbeeChannel") is not None: + if device.get("zigBeeChannel") is not None: attributes.append( self.build_attribute( device["hiloId"], "ZigbeeChannel", device["zigBeeChannel"] From c74fdc18e14b3429bdd1fb33963703f10956f133 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Mon, 26 Oct 2026 00:44:17 +0000 Subject: [PATCH 3/3] Add missing newline at end of GraphQL mapper test Ruff flags the missing trailing newline (W292). The pre-commit ruff hooks only cover pyhilo/ today, so CI did not catch it; fixing it here keeps this PR green once the hooks are extended to tests/. Co-Authored-By: Claude Opus 5.5 --- tests/test_graphql_value_mapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_graphql_value_mapper.py b/tests/test_graphql_value_mapper.py index 245dce2..3dac709 100644 --- a/tests/test_graphql_value_mapper.py +++ b/tests/test_graphql_value_mapper.py @@ -20,4 +20,4 @@ def test_smart_meter_maps_zigbee_channel() -> None: ) channel = [a["value"] for a in attributes if a["attribute"] == "ZigbeeChannel"] - assert channel == [24] \ No newline at end of file + assert channel == [24]