From bb278a069e30455ed946a77fbe1ecb011645b9ba Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:41:51 -0500 Subject: [PATCH] =?UTF-8?q?Ajout=20test=20pour=20l'humidit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_graphql_value_mapper.py | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_graphql_value_mapper.py b/tests/test_graphql_value_mapper.py index 3dac709..1239e43 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,33 @@ def test_smart_meter_maps_zigbee_channel() -> None: channel = [a["value"] for a in attributes if a["attribute"] == "ZigbeeChannel"] assert channel == [24] + + +@pytest.mark.parametrize( + ("ambient_humidity", "expected"), + [ + pytest.param(45.5, [45.5], id="reading"), + pytest.param(0, [], id="no-sensor-zero"), + pytest.param(None, [], id="null"), + ], +) +def test_thermostat_humidity_skips_missing_sensor( + ambient_humidity: float | None, expected: list[float] +) -> None: + """Models without a humidity sensor report 0, which must not surface as 0%.""" + device = _device("onAnyDeviceUpdated-tstat.json") + device["ambientHumidity"] = ambient_humidity + + attributes = GraphqlValueMapper().map_device_subscription_values(device) + + assert [a["value"] for a in attributes if a["attribute"] == "Humidity"] == expected + + +def test_thermostat_humidity_absent_field() -> None: + """Payloads that omit ambientHumidity produce no Humidity attribute.""" + device = _device("onAnyDeviceUpdated-tstat.json") + del device["ambientHumidity"] + + attributes = GraphqlValueMapper().map_device_subscription_values(device) + + assert not [a for a in attributes if a["attribute"] == "Humidity"]