Skip to content

Commit 79fdbf5

Browse files
ic-dev21claude
andcommitted
Merge main into bugfix/disconnected-attribute
The humidity tests from #491 and the disconnected tests on this branch were both appended to the end of test_graphql_value_mapper.py; keep both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 parents 484d57d + 71e24b7 commit 79fdbf5

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎pyhilo/device/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
6-
from datetime import datetime
6+
from datetime import UTC, datetime
77
from typing import TYPE_CHECKING, Any, Dict, Union, cast
88

99
from pyhilo.const import (
@@ -62,7 +62,7 @@ def update(self, **kwargs: Dict[str, Union[str, int, Dict]]) -> None:
6262
"deviceId": self.id,
6363
"hiloId": self.hilo_id,
6464
"locationId": self.location_id,
65-
"timeStampUTC": datetime.utcnow().isoformat(),
65+
"timeStampUTC": datetime.now(UTC).isoformat(),
6666
"value": value,
6767
"device_attribute": DeviceAttribute(orig_att, reading_att),
6868
}
@@ -127,7 +127,7 @@ async def _set_attribute(
127127
**{
128128
"deviceId": self.id,
129129
"locationId": self.location_id,
130-
"timeStampUTC": datetime.utcnow().isoformat(),
130+
"timeStampUTC": datetime.now(UTC).isoformat(),
131131
"value": value,
132132
"device_attribute": attribute,
133133
} # type: ignore

‎tests/test_graphql_value_mapper.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,33 @@ def test_hub_disconnected_follows_connection_status(
9494
) -> None:
9595
"""The gateway's Disconnected attribute is derived from the string status."""
9696
assert _disconnected_values(_hub(connection_status)) == {expected}
97+
98+
99+
@pytest.mark.parametrize(
100+
("ambient_humidity", "expected"),
101+
[
102+
pytest.param(45.5, [45.5], id="reading"),
103+
pytest.param(0, [], id="no-sensor-zero"),
104+
pytest.param(None, [], id="null"),
105+
],
106+
)
107+
def test_thermostat_humidity_skips_missing_sensor(
108+
ambient_humidity: float | None, expected: list[float]
109+
) -> None:
110+
"""Models without a humidity sensor report 0, which must not surface as 0%."""
111+
device = _device("onAnyDeviceUpdated-tstat.json")
112+
device["ambientHumidity"] = ambient_humidity
113+
114+
attributes = GraphqlValueMapper().map_device_subscription_values(device)
115+
116+
assert [a["value"] for a in attributes if a["attribute"] == "Humidity"] == expected
117+
118+
119+
def test_thermostat_humidity_absent_field() -> None:
120+
"""Payloads that omit ambientHumidity produce no Humidity attribute."""
121+
device = _device("onAnyDeviceUpdated-tstat.json")
122+
del device["ambientHumidity"]
123+
124+
attributes = GraphqlValueMapper().map_device_subscription_values(device)
125+
126+
assert not [a for a in attributes if a["attribute"] == "Humidity"]

0 commit comments

Comments
 (0)