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"] diff --git a/tests/test_graphql_value_mapper.py b/tests/test_graphql_value_mapper.py new file mode 100644 index 0000000..3dac709 --- /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]