carrier-api 3.6.0__tar.gz → 3.6.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {carrier_api-3.6.0/src/carrier_api.egg-info → carrier_api-3.6.2}/PKG-INFO +1 -1
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/api_connection_graphql.py +3 -3
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/api_websocket_data_updater.py +14 -6
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/const.py +1 -1
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/util.py +10 -3
- {carrier_api-3.6.0 → carrier_api-3.6.2/src/carrier_api.egg-info}/PKG-INFO +1 -1
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_models.py +40 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_websocket_data_updater.py +71 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/LICENSE +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/README.md +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/pyproject.toml +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/setup.cfg +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/__init__.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/api_websocket.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/config.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/energy.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/entry_level.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/errors.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/live_smoke_test.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/profile.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/py.typed +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/status.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api/system.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api.egg-info/SOURCES.txt +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api.egg-info/dependency_links.txt +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api.egg-info/requires.txt +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/src/carrier_api.egg-info/top_level.txt +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_api_connection_graphql.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_api_websocket.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_config.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_entry_level.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_fixture_contracts.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_live_smoke_test.py +0 -0
- {carrier_api-3.6.0 → carrier_api-3.6.2}/tests/test_workflows.py +0 -0
|
@@ -1024,13 +1024,13 @@ class ApiConnectionGraphql:
|
|
|
1024
1024
|
system_serial: Serial number of the system to update.
|
|
1025
1025
|
zone_id: Carrier zone identifier.
|
|
1026
1026
|
activity_type: Activity to update.
|
|
1027
|
-
heat_set_point:
|
|
1028
|
-
cool_set_point:
|
|
1027
|
+
heat_set_point: requested heat set point as Carrier expects it.
|
|
1028
|
+
cool_set_point: requested cool set point as Carrier expects it.
|
|
1029
1029
|
fan_mode: Optional fan mode to include in the activity update.
|
|
1030
1030
|
|
|
1031
1031
|
Returns:
|
|
1032
1032
|
The decoded mutation response.
|
|
1033
|
-
|
|
1033
|
+
|
|
1034
1034
|
Raises:
|
|
1035
1035
|
ValueError: If ``fan_mode`` or ``activity_type`` is not a valid enum
|
|
1036
1036
|
member.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Apply Carrier realtime websocket messages to in-memory system models."""
|
|
2
2
|
|
|
3
|
+
from copy import deepcopy
|
|
3
4
|
from datetime import UTC, datetime
|
|
4
5
|
from json import loads
|
|
5
6
|
from logging import getLogger
|
|
@@ -124,6 +125,11 @@ class WebsocketDataUpdater:
|
|
|
124
125
|
``diagnostic-device-info`` messages merge their system and unit readings
|
|
125
126
|
into the raw status payload.
|
|
126
127
|
|
|
128
|
+
Each message is merged into a copy of the raw payload, and the stored
|
|
129
|
+
payload is only replaced once the rebuilt model parses. A message that
|
|
130
|
+
fails to parse therefore raises without leaving its values behind in
|
|
131
|
+
``raw``, where they would fail every later message for that system too.
|
|
132
|
+
|
|
127
133
|
Args:
|
|
128
134
|
websocket_message: JSON websocket message text from Carrier realtime
|
|
129
135
|
updates.
|
|
@@ -147,24 +153,26 @@ class WebsocketDataUpdater:
|
|
|
147
153
|
match message_type or message_name:
|
|
148
154
|
case "InfinityStatus":
|
|
149
155
|
_LOGGER.debug("InfinityStatus received: %s", websocket_message)
|
|
156
|
+
status_raw = deepcopy(system.status.raw)
|
|
150
157
|
zones = websocket_message_json.pop("zones", [])
|
|
151
158
|
for zone in zones:
|
|
152
159
|
_timestamp = zone.pop("timestamp", None)
|
|
153
|
-
stale_zone = find_by_id(
|
|
160
|
+
stale_zone = find_by_id(status_raw["zones"], zone["id"])
|
|
154
161
|
always_merger.merge(stale_zone, zone)
|
|
155
|
-
merged_status = always_merger.merge(
|
|
162
|
+
merged_status = always_merger.merge(status_raw, websocket_message_json)
|
|
156
163
|
merged_status.update({"utcTime": datetime.now(UTC).isoformat()})
|
|
157
164
|
system.status = Status(merged_status)
|
|
158
165
|
case "InfinityConfig":
|
|
159
166
|
_message_id = websocket_message_json.pop("id", None)
|
|
160
167
|
_config_id = websocket_message_json.pop("infinitySystemConfigurationId", None)
|
|
161
168
|
_LOGGER.debug("InfinityConfig received: %s", websocket_message)
|
|
169
|
+
config_raw = deepcopy(system.config.raw)
|
|
162
170
|
zones = websocket_message_json.pop("zones", [])
|
|
163
171
|
for zone in zones:
|
|
164
172
|
_timestamp = zone.pop("timestamp", None)
|
|
165
173
|
if "id" in zone:
|
|
166
174
|
zone_id = zone["id"]
|
|
167
|
-
stale_zone = find_by_id(
|
|
175
|
+
stale_zone = find_by_id(config_raw["zones"], zone_id)
|
|
168
176
|
activities = zone.pop("activities", [])
|
|
169
177
|
for activity in activities:
|
|
170
178
|
_timestamp = activity.pop("timestamp", None)
|
|
@@ -174,8 +182,8 @@ class WebsocketDataUpdater:
|
|
|
174
182
|
if stale_activity is not None:
|
|
175
183
|
always_merger.merge(stale_activity, activity)
|
|
176
184
|
always_merger.merge(stale_zone, zone)
|
|
177
|
-
always_merger.merge(
|
|
178
|
-
system.config = Config(
|
|
185
|
+
merged_config = always_merger.merge(config_raw, websocket_message_json)
|
|
186
|
+
system.config = Config(merged_config)
|
|
179
187
|
case "diagnostic-device-info":
|
|
180
188
|
_LOGGER.debug("diagnostic-device-info received: %s", websocket_message)
|
|
181
189
|
value = websocket_message_json.pop("value", None)
|
|
@@ -186,7 +194,7 @@ class WebsocketDataUpdater:
|
|
|
186
194
|
if not status_values:
|
|
187
195
|
_LOGGER.debug("diagnostic-device-info carried no known sections, skipping")
|
|
188
196
|
return
|
|
189
|
-
merged_status = always_merger.merge(system.status.raw, status_values)
|
|
197
|
+
merged_status = always_merger.merge(deepcopy(system.status.raw), status_values)
|
|
190
198
|
merged_status.update({"utcTime": datetime.now(UTC).isoformat()})
|
|
191
199
|
system.status = Status(merged_status)
|
|
192
200
|
case _:
|
|
@@ -16,8 +16,10 @@ def safely_get_json_value(
|
|
|
16
16
|
|
|
17
17
|
Dot-separated key segments traverse dictionaries and lists. Missing keys,
|
|
18
18
|
invalid indexes, and incompatible container types resolve to ``None`` so
|
|
19
|
-
model constructors can tolerate partial Carrier payloads.
|
|
20
|
-
|
|
19
|
+
model constructors can tolerate partial Carrier payloads. Carrier sometimes
|
|
20
|
+
wraps a scalar in a single-key object, either ``{"_": value}`` or one keyed
|
|
21
|
+
by the field's own name, so those are unwrapped to the inner value. String
|
|
22
|
+
values of ``"none"`` are normalized to ``None`` before optional casting.
|
|
21
23
|
|
|
22
24
|
Args:
|
|
23
25
|
json: Mapping or list to traverse.
|
|
@@ -39,6 +41,11 @@ def safely_get_json_value(
|
|
|
39
41
|
except TypeError, KeyError, ValueError, IndexError:
|
|
40
42
|
value = None
|
|
41
43
|
|
|
44
|
+
if isinstance(value, Mapping) and len(value) == 1:
|
|
45
|
+
((wrapper_key, wrapped_value),) = value.items()
|
|
46
|
+
if wrapper_key in ("_", key.rsplit(".", maxsplit=1)[-1]):
|
|
47
|
+
value = wrapped_value
|
|
48
|
+
|
|
42
49
|
try:
|
|
43
50
|
if value.lower() == "none":
|
|
44
51
|
value = None
|
|
@@ -48,7 +55,7 @@ def safely_get_json_value(
|
|
|
48
55
|
if callable_to_cast is not None and value is not None:
|
|
49
56
|
try:
|
|
50
57
|
value = callable_to_cast(value)
|
|
51
|
-
except ValueError:
|
|
58
|
+
except TypeError, ValueError:
|
|
52
59
|
_LOGGER.exception("Unable to cast JSON value")
|
|
53
60
|
value = None
|
|
54
61
|
return value
|
|
@@ -688,6 +688,46 @@ def test_safely_get_json_value_handles_nested_lists_none_and_cast_failures() ->
|
|
|
688
688
|
assert safely_get_json_value([], "missing") is None
|
|
689
689
|
|
|
690
690
|
|
|
691
|
+
def test_safely_get_json_value_unwraps_single_value_objects() -> None:
|
|
692
|
+
"""Unwrap Carrier's ``{"_": value}`` and self-named single-value objects."""
|
|
693
|
+
payload = {
|
|
694
|
+
"blwrpm": {"_": "450"},
|
|
695
|
+
"aclinecurrent": {"aclinecurrent": "2.1"},
|
|
696
|
+
"opstat": {"_": "none"},
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
assert safely_get_json_value(payload, "blwrpm", int) == 450
|
|
700
|
+
assert safely_get_json_value(payload, "blwrpm") == "450"
|
|
701
|
+
assert safely_get_json_value(payload, "aclinecurrent", float) == 2.1
|
|
702
|
+
assert safely_get_json_value(payload, "opstat") is None
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def test_safely_get_json_value_returns_none_when_cast_raises_type_error() -> None:
|
|
706
|
+
"""Return None rather than raising when a value's type cannot be cast."""
|
|
707
|
+
payload = {"cfm": {"min": 400, "max": 600}, "linevolt": ["249"]}
|
|
708
|
+
|
|
709
|
+
assert safely_get_json_value(payload, "cfm", int) is None
|
|
710
|
+
assert safely_get_json_value(payload, "linevolt", int) is None
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
def test_status_reads_wrapped_unit_values() -> None:
|
|
714
|
+
"""Build unit readings from wrapped values instead of failing the status."""
|
|
715
|
+
status = Status(
|
|
716
|
+
{
|
|
717
|
+
"cfgem": "F",
|
|
718
|
+
"utcTime": "2026-09-22T18:42:50.000Z",
|
|
719
|
+
"zones": [],
|
|
720
|
+
"idu": {"blwrpm": {"_": "450"}, "cfm": {"cfm": "400"}},
|
|
721
|
+
"odu": {"linevolt": {"_": "249"}},
|
|
722
|
+
}
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
assert status.blower_rpm == 450
|
|
726
|
+
assert status.airflow_cfm == 400
|
|
727
|
+
assert status.outdoor_unit is not None
|
|
728
|
+
assert status.outdoor_unit.line_voltage == 249
|
|
729
|
+
|
|
730
|
+
|
|
691
731
|
def test_activity_and_fan_string_representations() -> None:
|
|
692
732
|
"""Serialize standalone config activity values."""
|
|
693
733
|
activity = ConfigZoneActivity(
|
|
@@ -551,3 +551,74 @@ async def test_unknown_wrapped_message_is_still_logged(
|
|
|
551
551
|
|
|
552
552
|
assert "Received unknown message" in caplog.text
|
|
553
553
|
assert carrier_system.status.as_dict() == original_status_payload
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
@pytest.mark.asyncio
|
|
557
|
+
async def test_status_message_that_fails_to_parse_leaves_status_untouched(
|
|
558
|
+
data_updater: WebsocketDataUpdater,
|
|
559
|
+
carrier_system: System,
|
|
560
|
+
) -> None:
|
|
561
|
+
"""Keep a status message that cannot be parsed out of the stored raw status.
|
|
562
|
+
|
|
563
|
+
A merged value that fails ``Status`` would otherwise stay in ``raw`` and
|
|
564
|
+
fail every later status message too.
|
|
565
|
+
|
|
566
|
+
Args:
|
|
567
|
+
data_updater: Websocket updater under test.
|
|
568
|
+
carrier_system: Prepared system model that receives the update.
|
|
569
|
+
"""
|
|
570
|
+
zone_id = carrier_system.status.zones[0].api_id
|
|
571
|
+
original_status_payload = carrier_system.status.as_dict()
|
|
572
|
+
bad_message = json.dumps(
|
|
573
|
+
{
|
|
574
|
+
"messageType": "InfinityStatus",
|
|
575
|
+
"deviceId": "SERIALXXX",
|
|
576
|
+
"zones": [{"id": zone_id, "fan": "turbo"}],
|
|
577
|
+
}
|
|
578
|
+
)
|
|
579
|
+
good_message = json.dumps(
|
|
580
|
+
{
|
|
581
|
+
"messageType": "InfinityStatus",
|
|
582
|
+
"deviceId": "SERIALXXX",
|
|
583
|
+
"zones": [{"id": zone_id, "zoneconditioning": "idle"}],
|
|
584
|
+
}
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
with pytest.raises(ValueError, match="turbo"):
|
|
588
|
+
await data_updater.message_handler(bad_message)
|
|
589
|
+
|
|
590
|
+
assert carrier_system.status.as_dict() == original_status_payload
|
|
591
|
+
assert "turbo" not in json.dumps(carrier_system.status.raw)
|
|
592
|
+
|
|
593
|
+
await data_updater.message_handler(good_message)
|
|
594
|
+
|
|
595
|
+
assert carrier_system.status.zones[0].conditioning == "idle"
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
@pytest.mark.asyncio
|
|
599
|
+
async def test_config_message_that_fails_to_parse_leaves_config_untouched(
|
|
600
|
+
data_updater: WebsocketDataUpdater,
|
|
601
|
+
carrier_system: System,
|
|
602
|
+
) -> None:
|
|
603
|
+
"""Keep a config message that cannot be parsed out of the stored raw config.
|
|
604
|
+
|
|
605
|
+
Args:
|
|
606
|
+
data_updater: Websocket updater under test.
|
|
607
|
+
carrier_system: Prepared system model that receives the update.
|
|
608
|
+
"""
|
|
609
|
+
zone = carrier_system.config.raw["zones"][0]
|
|
610
|
+
activity_id = zone["activities"][0]["id"]
|
|
611
|
+
original_config_payload = carrier_system.config.as_dict()
|
|
612
|
+
bad_message = json.dumps(
|
|
613
|
+
{
|
|
614
|
+
"messageType": "InfinityConfig",
|
|
615
|
+
"deviceId": "SERIALXXX",
|
|
616
|
+
"zones": [{"id": zone["id"], "activities": [{"id": activity_id, "type": "bogus"}]}],
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
with pytest.raises(ValueError, match="bogus"):
|
|
621
|
+
await data_updater.message_handler(bad_message)
|
|
622
|
+
|
|
623
|
+
assert carrier_system.config.as_dict() == original_config_payload
|
|
624
|
+
assert "bogus" not in json.dumps(carrier_system.config.raw)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|