python-duco-connectivity 0.13.0__tar.gz → 0.14.0__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.
- {python_duco_connectivity-0.13.0/src/python_duco_connectivity.egg-info → python_duco_connectivity-0.14.0}/PKG-INFO +24 -12
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/README.md +23 -11
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/pyproject.toml +1 -1
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/client.py +50 -22
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/models.py +87 -4
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0/src/python_duco_connectivity.egg-info}/PKG-INFO +24 -12
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_api_reference.py +2 -1
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_client.py +207 -15
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_models.py +151 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/LICENSE +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/setup.cfg +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/__init__.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/__main__.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/cli.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/exceptions.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/py.typed +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/python_duco_connectivity.egg-info/SOURCES.txt +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/python_duco_connectivity.egg-info/dependency_links.txt +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/python_duco_connectivity.egg-info/entry_points.txt +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/python_duco_connectivity.egg-info/requires.txt +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/python_duco_connectivity.egg-info/top_level.txt +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_cli.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_exceptions.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_local_sample_validation.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_pytest_live_support.py +0 -0
- {python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_replay_helpers.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-duco-connectivity
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: Async HTTP client for the local Duco Connectivity API
|
|
5
5
|
Author: Ronald van der Meer
|
|
6
6
|
License-Expression: MIT
|
|
@@ -64,27 +64,39 @@ in the development examples below.
|
|
|
64
64
|
- asynchronous communication via `aiohttp`
|
|
65
65
|
- typed stable config families for the documented `/config` branches
|
|
66
66
|
- typed helpers for stable `/info` fields such as heat recovery filter time
|
|
67
|
-
- optional
|
|
67
|
+
- natural empty results for optional capability discovery and explicit errors
|
|
68
|
+
for strict capability access
|
|
68
69
|
- typed models that stay close to the API response shape
|
|
69
70
|
- preserved `raw_payload` data on typed response models for forward compatibility
|
|
70
71
|
|
|
71
72
|
## Error handling
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
Discovery-style helpers use their natural empty result when a Duco box reports
|
|
75
|
+
an optional capability as unsupported: filter time returns `None`, ventilation
|
|
76
|
+
temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
|
|
77
|
+
targets return `{}`. Malformed responses and operational failures remain
|
|
78
|
+
exceptions. The strict parameter-specific bypass helper raises
|
|
79
|
+
`DucoUnsupportedCapabilityError` for an unsupported target; this
|
|
80
|
+
`DucoResponseError` subclass preserves the HTTP status, path, and response body.
|
|
81
|
+
The bypass-target helpers only return models with complete and coherent value,
|
|
82
|
+
minimum, increment, and maximum metadata. Bulk reads omit an invalid individual
|
|
83
|
+
zone without suppressing valid zones. Parameter-specific reads and write
|
|
84
|
+
responses raise `DucoError` when the requested target is missing, incomplete,
|
|
85
|
+
or inconsistent. `BypassSupplyTemperatureTarget.validate_value()` checks a
|
|
86
|
+
Celsius value against the target-specific range and step, while
|
|
87
|
+
`normalize_value()` rounds converted values to the nearest supported step. Pass
|
|
88
|
+
the target to `async_set_bypass_supply_temperature_target(..., target=target)`
|
|
89
|
+
to validate a write without an additional read. Calls without `target` retain
|
|
90
|
+
the legacy finite and exact-decicelsius validation temporarily.
|
|
82
91
|
|
|
83
92
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
84
93
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
|
85
94
|
API value in `raw_status`; an unrecognized future value produces `status=None`
|
|
86
95
|
without discarding the raw value. Subsystem names remain unfiltered so future
|
|
87
|
-
components are available to downstream consumers.
|
|
96
|
+
components are available to downstream consumers. Direct construction using a
|
|
97
|
+
pre-0.13 raw status string remains compatible and derives `raw_status`
|
|
98
|
+
automatically; callers using a normalized `DiagStatus` must provide
|
|
99
|
+
`raw_status` explicitly.
|
|
88
100
|
|
|
89
101
|
## Getting started
|
|
90
102
|
|
|
@@ -32,27 +32,39 @@ in the development examples below.
|
|
|
32
32
|
- asynchronous communication via `aiohttp`
|
|
33
33
|
- typed stable config families for the documented `/config` branches
|
|
34
34
|
- typed helpers for stable `/info` fields such as heat recovery filter time
|
|
35
|
-
- optional
|
|
35
|
+
- natural empty results for optional capability discovery and explicit errors
|
|
36
|
+
for strict capability access
|
|
36
37
|
- typed models that stay close to the API response shape
|
|
37
38
|
- preserved `raw_payload` data on typed response models for forward compatibility
|
|
38
39
|
|
|
39
40
|
## Error handling
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
Discovery-style helpers use their natural empty result when a Duco box reports
|
|
43
|
+
an optional capability as unsupported: filter time returns `None`, ventilation
|
|
44
|
+
temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
|
|
45
|
+
targets return `{}`. Malformed responses and operational failures remain
|
|
46
|
+
exceptions. The strict parameter-specific bypass helper raises
|
|
47
|
+
`DucoUnsupportedCapabilityError` for an unsupported target; this
|
|
48
|
+
`DucoResponseError` subclass preserves the HTTP status, path, and response body.
|
|
49
|
+
The bypass-target helpers only return models with complete and coherent value,
|
|
50
|
+
minimum, increment, and maximum metadata. Bulk reads omit an invalid individual
|
|
51
|
+
zone without suppressing valid zones. Parameter-specific reads and write
|
|
52
|
+
responses raise `DucoError` when the requested target is missing, incomplete,
|
|
53
|
+
or inconsistent. `BypassSupplyTemperatureTarget.validate_value()` checks a
|
|
54
|
+
Celsius value against the target-specific range and step, while
|
|
55
|
+
`normalize_value()` rounds converted values to the nearest supported step. Pass
|
|
56
|
+
the target to `async_set_bypass_supply_temperature_target(..., target=target)`
|
|
57
|
+
to validate a write without an additional read. Calls without `target` retain
|
|
58
|
+
the legacy finite and exact-decicelsius validation temporarily.
|
|
50
59
|
|
|
51
60
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
52
61
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
|
53
62
|
API value in `raw_status`; an unrecognized future value produces `status=None`
|
|
54
63
|
without discarding the raw value. Subsystem names remain unfiltered so future
|
|
55
|
-
components are available to downstream consumers.
|
|
64
|
+
components are available to downstream consumers. Direct construction using a
|
|
65
|
+
pre-0.13 raw status string remains compatible and derives `raw_status`
|
|
66
|
+
automatically; callers using a normalized `DiagStatus` must provide
|
|
67
|
+
`raw_status` explicitly.
|
|
56
68
|
|
|
57
69
|
## Getting started
|
|
58
70
|
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/client.py
RENAMED
|
@@ -373,14 +373,40 @@ class DucoClient:
|
|
|
373
373
|
value: ConfigValue,
|
|
374
374
|
) -> BypassSupplyTemperatureTarget:
|
|
375
375
|
"""Convert a raw config value into a Celsius convenience model."""
|
|
376
|
+
parameter = f"TempSupTgtZone{zone_id}"
|
|
377
|
+
if value.minimum is None:
|
|
378
|
+
msg = f"Invalid {parameter}: missing Min"
|
|
379
|
+
raise DucoError(msg)
|
|
380
|
+
if value.increment is None:
|
|
381
|
+
msg = f"Invalid {parameter}: missing Inc"
|
|
382
|
+
raise DucoError(msg)
|
|
383
|
+
if value.maximum is None:
|
|
384
|
+
msg = f"Invalid {parameter}: missing Max"
|
|
385
|
+
raise DucoError(msg)
|
|
386
|
+
|
|
387
|
+
target_value = cls._decicelsius_to_celsius(value.value)
|
|
388
|
+
minimum = cls._decicelsius_to_celsius(value.minimum)
|
|
389
|
+
increment = cls._decicelsius_to_celsius(value.increment)
|
|
390
|
+
maximum = cls._decicelsius_to_celsius(value.maximum)
|
|
391
|
+
if increment <= 0:
|
|
392
|
+
msg = f"Invalid {parameter}: Inc must be greater than zero"
|
|
393
|
+
raise DucoError(msg)
|
|
394
|
+
if minimum > maximum:
|
|
395
|
+
msg = f"Invalid {parameter}: Min must not exceed Max"
|
|
396
|
+
raise DucoError(msg)
|
|
397
|
+
if not minimum <= target_value <= maximum:
|
|
398
|
+
msg = f"Invalid {parameter}: Val must be between Min and Max"
|
|
399
|
+
raise DucoError(msg)
|
|
400
|
+
if (value.value - value.minimum) % value.increment:
|
|
401
|
+
msg = f"Invalid {parameter}: Val must align with Inc relative to Min"
|
|
402
|
+
raise DucoError(msg)
|
|
403
|
+
|
|
376
404
|
return BypassSupplyTemperatureTarget(
|
|
377
405
|
zone_id=zone_id,
|
|
378
|
-
value=
|
|
379
|
-
minimum=
|
|
380
|
-
increment=
|
|
381
|
-
|
|
382
|
-
else cls._decicelsius_to_celsius(value.increment),
|
|
383
|
-
maximum=None if value.maximum is None else cls._decicelsius_to_celsius(value.maximum),
|
|
406
|
+
value=target_value,
|
|
407
|
+
minimum=minimum,
|
|
408
|
+
increment=increment,
|
|
409
|
+
maximum=maximum,
|
|
384
410
|
raw_payload=cls._preserve_raw_payload(value.raw_payload),
|
|
385
411
|
)
|
|
386
412
|
|
|
@@ -407,12 +433,16 @@ class DucoClient:
|
|
|
407
433
|
config: Config,
|
|
408
434
|
) -> dict[int, BypassSupplyTemperatureTarget]:
|
|
409
435
|
"""Read all bypass supply targets from a typed config response."""
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
436
|
+
targets: dict[int, BypassSupplyTemperatureTarget] = {}
|
|
437
|
+
for zone_id in range(1, 9):
|
|
438
|
+
try:
|
|
439
|
+
target = cls._extract_bypass_supply_temperature_target(config, zone_id)
|
|
440
|
+
except DucoError as err:
|
|
441
|
+
_LOGGER.debug("Skipping bypass target for zone %s: %s", zone_id, err)
|
|
442
|
+
continue
|
|
443
|
+
if target is not None:
|
|
444
|
+
targets[zone_id] = target
|
|
445
|
+
return targets
|
|
416
446
|
|
|
417
447
|
@staticmethod
|
|
418
448
|
def _read_scalar_value(payload: dict[str, Any], key: str) -> Any:
|
|
@@ -2264,11 +2294,7 @@ class DucoClient:
|
|
|
2264
2294
|
payload = await self.async_get_info(module=InfoModuleSelector.VENTILATION)
|
|
2265
2295
|
except DucoResponseError as err:
|
|
2266
2296
|
if _is_unsupported_optional_endpoint_error(err, "/info"):
|
|
2267
|
-
|
|
2268
|
-
err.status,
|
|
2269
|
-
err.path,
|
|
2270
|
-
err.body,
|
|
2271
|
-
) from err
|
|
2297
|
+
return VentilationTemperatureInfo()
|
|
2272
2298
|
raise
|
|
2273
2299
|
|
|
2274
2300
|
if not isinstance(payload, dict):
|
|
@@ -2344,11 +2370,7 @@ class DucoClient:
|
|
|
2344
2370
|
)
|
|
2345
2371
|
except DucoResponseError as err:
|
|
2346
2372
|
if _is_unsupported_optional_endpoint_error(err, "/config"):
|
|
2347
|
-
|
|
2348
|
-
err.status,
|
|
2349
|
-
err.path,
|
|
2350
|
-
err.body,
|
|
2351
|
-
) from err
|
|
2373
|
+
return {}
|
|
2352
2374
|
raise
|
|
2353
2375
|
return self._extract_bypass_supply_temperature_targets(config)
|
|
2354
2376
|
|
|
@@ -2356,9 +2378,15 @@ class DucoClient:
|
|
|
2356
2378
|
self,
|
|
2357
2379
|
zone_id: int,
|
|
2358
2380
|
temperature: float,
|
|
2381
|
+
*,
|
|
2382
|
+
target: BypassSupplyTemperatureTarget | None = None,
|
|
2359
2383
|
) -> BypassSupplyTemperatureTarget:
|
|
2360
2384
|
"""Set a bypass supply target through `/config` using Celsius input."""
|
|
2361
2385
|
parameter = self._validate_bypass_zone_id(zone_id)
|
|
2386
|
+
if target is not None:
|
|
2387
|
+
if target.zone_id != zone_id:
|
|
2388
|
+
raise ValueError("target zone_id must match zone_id")
|
|
2389
|
+
target.validate_value(temperature)
|
|
2362
2390
|
raw_value = self._celsius_to_decicelsius(
|
|
2363
2391
|
temperature,
|
|
2364
2392
|
path=f"bypass_supply_temperature_target[{zone_id}]",
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/models.py
RENAMED
|
@@ -4,6 +4,7 @@ import logging
|
|
|
4
4
|
import re
|
|
5
5
|
import sys
|
|
6
6
|
from dataclasses import dataclass, field
|
|
7
|
+
from decimal import ROUND_DOWN, ROUND_HALF_UP, Decimal
|
|
7
8
|
from enum import StrEnum
|
|
8
9
|
from types import FrameType
|
|
9
10
|
from typing import Any, Self
|
|
@@ -948,11 +949,53 @@ class BypassSupplyTemperatureTarget:
|
|
|
948
949
|
|
|
949
950
|
zone_id: int
|
|
950
951
|
value: float
|
|
951
|
-
minimum: float
|
|
952
|
-
increment: float
|
|
953
|
-
maximum: float
|
|
952
|
+
minimum: float
|
|
953
|
+
increment: float
|
|
954
|
+
maximum: float
|
|
954
955
|
raw_payload: dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
|
|
955
956
|
|
|
957
|
+
@staticmethod
|
|
958
|
+
def _decimal_value(value: float, *, name: str) -> Decimal:
|
|
959
|
+
"""Return a finite numeric value as an exact decimal."""
|
|
960
|
+
if type(value) not in (int, float):
|
|
961
|
+
msg = f"{name} must be an int or float, got {type(value).__name__}"
|
|
962
|
+
raise ValueError(msg)
|
|
963
|
+
decimal_value = Decimal(str(value))
|
|
964
|
+
if not decimal_value.is_finite():
|
|
965
|
+
msg = f"{name} must be finite"
|
|
966
|
+
raise ValueError(msg)
|
|
967
|
+
return decimal_value
|
|
968
|
+
|
|
969
|
+
def _decimal_range(self) -> tuple[Decimal, Decimal, Decimal]:
|
|
970
|
+
"""Return validated target metadata as exact decimals."""
|
|
971
|
+
minimum = self._decimal_value(self.minimum, name="minimum")
|
|
972
|
+
increment = self._decimal_value(self.increment, name="increment")
|
|
973
|
+
maximum = self._decimal_value(self.maximum, name="maximum")
|
|
974
|
+
if increment <= 0:
|
|
975
|
+
raise ValueError("increment must be greater than zero")
|
|
976
|
+
if minimum > maximum:
|
|
977
|
+
raise ValueError("minimum must not exceed maximum")
|
|
978
|
+
return minimum, increment, maximum
|
|
979
|
+
|
|
980
|
+
def validate_value(self, value: float) -> float:
|
|
981
|
+
"""Return an unchanged value that satisfies this target's capabilities."""
|
|
982
|
+
decimal_value = self._decimal_value(value, name="value")
|
|
983
|
+
minimum, increment, maximum = self._decimal_range()
|
|
984
|
+
if not minimum <= decimal_value <= maximum:
|
|
985
|
+
raise ValueError("value must be between minimum and maximum")
|
|
986
|
+
if (decimal_value - minimum) % increment:
|
|
987
|
+
raise ValueError("value must align with increment relative to minimum")
|
|
988
|
+
return value
|
|
989
|
+
|
|
990
|
+
def normalize_value(self, value: float) -> float:
|
|
991
|
+
"""Round a value to the nearest supported target step."""
|
|
992
|
+
decimal_value = self._decimal_value(value, name="value")
|
|
993
|
+
minimum, increment, maximum = self._decimal_range()
|
|
994
|
+
steps = ((decimal_value - minimum) / increment).to_integral_value(rounding=ROUND_HALF_UP)
|
|
995
|
+
maximum_steps = ((maximum - minimum) / increment).to_integral_value(rounding=ROUND_DOWN)
|
|
996
|
+
normalized_steps = min(max(steps, Decimal()), maximum_steps)
|
|
997
|
+
return float(minimum + normalized_steps * increment)
|
|
998
|
+
|
|
956
999
|
|
|
957
1000
|
@dataclass(frozen=True, slots=True)
|
|
958
1001
|
class ConfigValue:
|
|
@@ -1575,7 +1618,7 @@ class NodeOverview:
|
|
|
1575
1618
|
raw_payload: dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
|
|
1576
1619
|
|
|
1577
1620
|
|
|
1578
|
-
@dataclass(frozen=True, slots=True)
|
|
1621
|
+
@dataclass(frozen=True, slots=True, init=False)
|
|
1579
1622
|
class DiagComponent:
|
|
1580
1623
|
"""Health state for a diagnostic subsystem."""
|
|
1581
1624
|
|
|
@@ -1584,6 +1627,46 @@ class DiagComponent:
|
|
|
1584
1627
|
raw_status: str
|
|
1585
1628
|
raw_payload: dict[str, Any] = field(default_factory=dict, repr=False, compare=False)
|
|
1586
1629
|
|
|
1630
|
+
def __init__(
|
|
1631
|
+
self,
|
|
1632
|
+
component: str,
|
|
1633
|
+
status: DiagStatus | str | None,
|
|
1634
|
+
raw_status: str | dict[str, Any] | None = None,
|
|
1635
|
+
raw_payload: dict[str, Any] | None = None,
|
|
1636
|
+
) -> None:
|
|
1637
|
+
"""Initialize a diagnostic subsystem with legacy argument compatibility."""
|
|
1638
|
+
if isinstance(raw_status, dict):
|
|
1639
|
+
if raw_payload is not None:
|
|
1640
|
+
raise TypeError("raw_payload was provided more than once")
|
|
1641
|
+
raw_payload = raw_status
|
|
1642
|
+
raw_status = None
|
|
1643
|
+
if raw_status is not None and not isinstance(raw_status, str):
|
|
1644
|
+
raise TypeError("raw_status must be a string")
|
|
1645
|
+
if (
|
|
1646
|
+
isinstance(status, str)
|
|
1647
|
+
and not isinstance(status, DiagStatus)
|
|
1648
|
+
and raw_status is not None
|
|
1649
|
+
and raw_status != status
|
|
1650
|
+
):
|
|
1651
|
+
raise ValueError("raw_status must match status for raw API strings")
|
|
1652
|
+
|
|
1653
|
+
normalized_status: DiagStatus | None
|
|
1654
|
+
if isinstance(status, DiagStatus):
|
|
1655
|
+
normalized_status = status
|
|
1656
|
+
elif isinstance(status, str):
|
|
1657
|
+
normalized_status = DiagStatus.from_api_value(status)
|
|
1658
|
+
else:
|
|
1659
|
+
normalized_status = None
|
|
1660
|
+
if raw_status is None:
|
|
1661
|
+
if not isinstance(status, str) or isinstance(status, DiagStatus):
|
|
1662
|
+
raise TypeError("raw_status is required unless status is a raw API string")
|
|
1663
|
+
raw_status = status
|
|
1664
|
+
|
|
1665
|
+
object.__setattr__(self, "component", component)
|
|
1666
|
+
object.__setattr__(self, "status", normalized_status)
|
|
1667
|
+
object.__setattr__(self, "raw_status", raw_status)
|
|
1668
|
+
object.__setattr__(self, "raw_payload", {} if raw_payload is None else raw_payload)
|
|
1669
|
+
|
|
1587
1670
|
|
|
1588
1671
|
@dataclass(frozen=True, slots=True)
|
|
1589
1672
|
class DiagInfo:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-duco-connectivity
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.14.0
|
|
4
4
|
Summary: Async HTTP client for the local Duco Connectivity API
|
|
5
5
|
Author: Ronald van der Meer
|
|
6
6
|
License-Expression: MIT
|
|
@@ -64,27 +64,39 @@ in the development examples below.
|
|
|
64
64
|
- asynchronous communication via `aiohttp`
|
|
65
65
|
- typed stable config families for the documented `/config` branches
|
|
66
66
|
- typed helpers for stable `/info` fields such as heat recovery filter time
|
|
67
|
-
- optional
|
|
67
|
+
- natural empty results for optional capability discovery and explicit errors
|
|
68
|
+
for strict capability access
|
|
68
69
|
- typed models that stay close to the API response shape
|
|
69
70
|
- preserved `raw_payload` data on typed response models for forward compatibility
|
|
70
71
|
|
|
71
72
|
## Error handling
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
Discovery-style helpers use their natural empty result when a Duco box reports
|
|
75
|
+
an optional capability as unsupported: filter time returns `None`, ventilation
|
|
76
|
+
temperatures return an empty `VentilationTemperatureInfo`, and bulk bypass
|
|
77
|
+
targets return `{}`. Malformed responses and operational failures remain
|
|
78
|
+
exceptions. The strict parameter-specific bypass helper raises
|
|
79
|
+
`DucoUnsupportedCapabilityError` for an unsupported target; this
|
|
80
|
+
`DucoResponseError` subclass preserves the HTTP status, path, and response body.
|
|
81
|
+
The bypass-target helpers only return models with complete and coherent value,
|
|
82
|
+
minimum, increment, and maximum metadata. Bulk reads omit an invalid individual
|
|
83
|
+
zone without suppressing valid zones. Parameter-specific reads and write
|
|
84
|
+
responses raise `DucoError` when the requested target is missing, incomplete,
|
|
85
|
+
or inconsistent. `BypassSupplyTemperatureTarget.validate_value()` checks a
|
|
86
|
+
Celsius value against the target-specific range and step, while
|
|
87
|
+
`normalize_value()` rounds converted values to the nearest supported step. Pass
|
|
88
|
+
the target to `async_set_bypass_supply_temperature_target(..., target=target)`
|
|
89
|
+
to validate a write without an additional read. Calls without `target` retain
|
|
90
|
+
the legacy finite and exact-decicelsius validation temporarily.
|
|
82
91
|
|
|
83
92
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
84
93
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
|
85
94
|
API value in `raw_status`; an unrecognized future value produces `status=None`
|
|
86
95
|
without discarding the raw value. Subsystem names remain unfiltered so future
|
|
87
|
-
components are available to downstream consumers.
|
|
96
|
+
components are available to downstream consumers. Direct construction using a
|
|
97
|
+
pre-0.13 raw status string remains compatible and derives `raw_status`
|
|
98
|
+
automatically; callers using a normalized `DiagStatus` must provide
|
|
99
|
+
`raw_status` explicitly.
|
|
88
100
|
|
|
89
101
|
## Getting started
|
|
90
102
|
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_api_reference.py
RENAMED
|
@@ -89,7 +89,8 @@ def test_api_reference_documents_optional_capability_contracts() -> None:
|
|
|
89
89
|
"""Optional endpoint return and exception contracts should stay explicit."""
|
|
90
90
|
content = render_api_reference()
|
|
91
91
|
|
|
92
|
-
assert "optional endpoint
|
|
92
|
+
assert "empty model when the optional endpoint is unsupported" in content
|
|
93
|
+
assert "empty mapping when the optional bypass endpoint is unsupported" in content
|
|
93
94
|
assert "without the requested target field in the response" in content
|
|
94
95
|
assert "optional target endpoint is unsupported" in content
|
|
95
96
|
|
|
@@ -3707,8 +3707,8 @@ async def test_get_ventilation_temperature_info_returns_empty_model_when_sensor_
|
|
|
3707
3707
|
assert payload.raw_payload == {}
|
|
3708
3708
|
|
|
3709
3709
|
|
|
3710
|
-
async def
|
|
3711
|
-
"""Unsupported ventilation
|
|
3710
|
+
async def test_get_ventilation_temperature_info_returns_empty_when_unsupported() -> None:
|
|
3711
|
+
"""Unsupported ventilation discovery should return an empty typed model."""
|
|
3712
3712
|
mock_response = _response(
|
|
3713
3713
|
status=400,
|
|
3714
3714
|
text_payload='{"Code":3,"Result":"FAILED"}',
|
|
@@ -3716,14 +3716,11 @@ async def test_get_ventilation_temperature_info_raises_for_unsupported_module()
|
|
|
3716
3716
|
|
|
3717
3717
|
async with aiohttp.ClientSession() as session:
|
|
3718
3718
|
client = DucoClient(session=session, host="192.0.2.94")
|
|
3719
|
-
with (
|
|
3720
|
-
|
|
3721
|
-
pytest.raises(DucoUnsupportedCapabilityError) as err_info,
|
|
3722
|
-
):
|
|
3723
|
-
await client.async_get_ventilation_temperature_info()
|
|
3719
|
+
with patch.object(session, "request", _request(mock_response)):
|
|
3720
|
+
payload = await client.async_get_ventilation_temperature_info()
|
|
3724
3721
|
|
|
3725
|
-
assert
|
|
3726
|
-
assert
|
|
3722
|
+
assert payload == VentilationTemperatureInfo()
|
|
3723
|
+
assert payload.raw_payload == {}
|
|
3727
3724
|
|
|
3728
3725
|
|
|
3729
3726
|
async def test_get_ventilation_temperature_info_reraises_other_client_errors() -> None:
|
|
@@ -3845,6 +3842,30 @@ async def test_get_bypass_supply_temperature_targets_returns_available_targets(
|
|
|
3845
3842
|
}
|
|
3846
3843
|
|
|
3847
3844
|
|
|
3845
|
+
@pytest.mark.parametrize("zone_count", [1, 2, 4])
|
|
3846
|
+
async def test_get_bypass_supply_temperature_targets_supports_zone_counts(
|
|
3847
|
+
zone_count: int,
|
|
3848
|
+
) -> None:
|
|
3849
|
+
"""Bulk bypass reads should support observed one-, two-, and four-zone layouts."""
|
|
3850
|
+
bypass = {
|
|
3851
|
+
f"TempSupTgtZone{zone_id}": {
|
|
3852
|
+
"Val": 180 + zone_id,
|
|
3853
|
+
"Min": 120,
|
|
3854
|
+
"Inc": 1,
|
|
3855
|
+
"Max": 220,
|
|
3856
|
+
}
|
|
3857
|
+
for zone_id in range(1, zone_count + 1)
|
|
3858
|
+
}
|
|
3859
|
+
mock_response = _response(json_payload={"HeatRecovery": {"Bypass": bypass}})
|
|
3860
|
+
|
|
3861
|
+
async with aiohttp.ClientSession() as session:
|
|
3862
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
3863
|
+
with patch.object(session, "request", _request(mock_response)):
|
|
3864
|
+
targets = await client.async_get_bypass_supply_temperature_targets()
|
|
3865
|
+
|
|
3866
|
+
assert set(targets) == set(range(1, zone_count + 1))
|
|
3867
|
+
|
|
3868
|
+
|
|
3848
3869
|
async def test_get_bypass_supply_temperature_targets_returns_empty_when_absent() -> None:
|
|
3849
3870
|
"""Bulk bypass target reads should omit targets absent from the response."""
|
|
3850
3871
|
mock_response = _response(json_payload={"HeatRecovery": {"Bypass": {}}})
|
|
@@ -3857,20 +3878,99 @@ async def test_get_bypass_supply_temperature_targets_returns_empty_when_absent()
|
|
|
3857
3878
|
assert targets == {}
|
|
3858
3879
|
|
|
3859
3880
|
|
|
3860
|
-
|
|
3861
|
-
""
|
|
3881
|
+
@pytest.mark.parametrize(
|
|
3882
|
+
("invalid_target", "message"),
|
|
3883
|
+
[
|
|
3884
|
+
pytest.param({"Val": 180, "Inc": 5, "Max": 220}, "missing Min", id="missing_min"),
|
|
3885
|
+
pytest.param({"Val": 180, "Min": 120, "Max": 220}, "missing Inc", id="missing_inc"),
|
|
3886
|
+
pytest.param({"Val": 180, "Min": 120, "Inc": 5}, "missing Max", id="missing_max"),
|
|
3887
|
+
pytest.param(
|
|
3888
|
+
{"Val": 180, "Min": 120, "Inc": 0, "Max": 220},
|
|
3889
|
+
"Inc must be greater than zero",
|
|
3890
|
+
id="zero_increment",
|
|
3891
|
+
),
|
|
3892
|
+
pytest.param(
|
|
3893
|
+
{"Val": 180, "Min": 220, "Inc": 5, "Max": 120},
|
|
3894
|
+
"Min must not exceed Max",
|
|
3895
|
+
id="inverted_range",
|
|
3896
|
+
),
|
|
3897
|
+
pytest.param(
|
|
3898
|
+
{"Val": 230, "Min": 120, "Inc": 5, "Max": 220},
|
|
3899
|
+
"Val must be between Min and Max",
|
|
3900
|
+
id="value_out_of_range",
|
|
3901
|
+
),
|
|
3902
|
+
pytest.param(
|
|
3903
|
+
{"Val": 182, "Min": 120, "Inc": 5, "Max": 220},
|
|
3904
|
+
"Val must align with Inc relative to Min",
|
|
3905
|
+
id="value_off_step",
|
|
3906
|
+
),
|
|
3907
|
+
],
|
|
3908
|
+
)
|
|
3909
|
+
async def test_get_bypass_supply_temperature_targets_omit_invalid_target(
|
|
3910
|
+
caplog: pytest.LogCaptureFixture,
|
|
3911
|
+
invalid_target: dict[str, int],
|
|
3912
|
+
message: str,
|
|
3913
|
+
) -> None:
|
|
3914
|
+
"""Invalid bulk targets should be isolated without suppressing valid zones."""
|
|
3915
|
+
payload = {
|
|
3916
|
+
"HeatRecovery": {
|
|
3917
|
+
"Bypass": {
|
|
3918
|
+
"TempSupTgtZone1": invalid_target,
|
|
3919
|
+
"TempSupTgtZone2": {"Val": 185, "Min": 120, "Inc": 5, "Max": 220},
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
mock_response = _response(json_payload=payload)
|
|
3924
|
+
|
|
3925
|
+
async with aiohttp.ClientSession() as session:
|
|
3926
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
3927
|
+
with (
|
|
3928
|
+
caplog.at_level(logging.DEBUG, logger="duco_connectivity.client"),
|
|
3929
|
+
patch.object(session, "request", _request(mock_response)),
|
|
3930
|
+
):
|
|
3931
|
+
targets = await client.async_get_bypass_supply_temperature_targets()
|
|
3932
|
+
|
|
3933
|
+
assert targets == {
|
|
3934
|
+
2: BypassSupplyTemperatureTarget(
|
|
3935
|
+
zone_id=2,
|
|
3936
|
+
value=18.5,
|
|
3937
|
+
minimum=12.0,
|
|
3938
|
+
increment=0.5,
|
|
3939
|
+
maximum=22.0,
|
|
3940
|
+
)
|
|
3941
|
+
}
|
|
3942
|
+
assert f"Skipping bypass target for zone 1: Invalid TempSupTgtZone1: {message}" in caplog.text
|
|
3943
|
+
assert str(invalid_target) not in caplog.text
|
|
3944
|
+
|
|
3945
|
+
|
|
3946
|
+
async def test_get_bypass_supply_temperature_target_rejects_invalid_metadata() -> None:
|
|
3947
|
+
"""Parameter-specific reads should reject incomplete target metadata."""
|
|
3862
3948
|
mock_response = _response(
|
|
3863
|
-
|
|
3864
|
-
text_payload='{"Code":3,"Result":"FAILED"}',
|
|
3949
|
+
json_payload={"HeatRecovery": {"Bypass": {"TempSupTgtZone1": {"Val": 180, "Min": 120}}}}
|
|
3865
3950
|
)
|
|
3866
3951
|
|
|
3867
3952
|
async with aiohttp.ClientSession() as session:
|
|
3868
3953
|
client = DucoClient(session=session, host="192.0.2.94")
|
|
3869
3954
|
with (
|
|
3870
3955
|
patch.object(session, "request", _request(mock_response)),
|
|
3871
|
-
pytest.raises(
|
|
3956
|
+
pytest.raises(DucoError, match="Invalid TempSupTgtZone1: missing Inc"),
|
|
3872
3957
|
):
|
|
3873
|
-
await client.
|
|
3958
|
+
await client.async_get_bypass_supply_temperature_target(1)
|
|
3959
|
+
|
|
3960
|
+
|
|
3961
|
+
async def test_get_bypass_supply_temperature_targets_returns_empty_when_unsupported() -> None:
|
|
3962
|
+
"""Unsupported bulk bypass discovery should return an empty mapping."""
|
|
3963
|
+
mock_response = _response(
|
|
3964
|
+
status=400,
|
|
3965
|
+
text_payload='{"Code":3,"Result":"FAILED"}',
|
|
3966
|
+
)
|
|
3967
|
+
|
|
3968
|
+
async with aiohttp.ClientSession() as session:
|
|
3969
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
3970
|
+
with patch.object(session, "request", _request(mock_response)):
|
|
3971
|
+
targets = await client.async_get_bypass_supply_temperature_targets()
|
|
3972
|
+
|
|
3973
|
+
assert targets == {}
|
|
3874
3974
|
|
|
3875
3975
|
|
|
3876
3976
|
async def test_get_bypass_supply_temperature_targets_reraises_other_client_errors() -> None:
|
|
@@ -3975,6 +4075,98 @@ async def test_set_bypass_supply_temperature_target_serializes_decicelsius(
|
|
|
3975
4075
|
assert kwargs["headers"] == {"Content-Type": "application/json"}
|
|
3976
4076
|
|
|
3977
4077
|
|
|
4078
|
+
async def test_set_bypass_supply_temperature_target_validates_against_target(
|
|
4079
|
+
config_data: dict[str, object],
|
|
4080
|
+
) -> None:
|
|
4081
|
+
"""Metadata-aware writes should validate and issue one PATCH without a GET."""
|
|
4082
|
+
target = BypassSupplyTemperatureTarget(
|
|
4083
|
+
zone_id=2,
|
|
4084
|
+
value=18.5,
|
|
4085
|
+
minimum=12.0,
|
|
4086
|
+
increment=0.5,
|
|
4087
|
+
maximum=22.0,
|
|
4088
|
+
)
|
|
4089
|
+
mock_response = _response(json_payload=config_data)
|
|
4090
|
+
|
|
4091
|
+
async with aiohttp.ClientSession() as session:
|
|
4092
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
4093
|
+
request = MagicMock(return_value=_request_context(mock_response))
|
|
4094
|
+
with patch.object(session, "request", request):
|
|
4095
|
+
await client.async_set_bypass_supply_temperature_target(
|
|
4096
|
+
2,
|
|
4097
|
+
18.5,
|
|
4098
|
+
target=target,
|
|
4099
|
+
)
|
|
4100
|
+
|
|
4101
|
+
request.assert_called_once()
|
|
4102
|
+
assert request.call_args.args[:2] == ("PATCH", "http://192.0.2.94/config")
|
|
4103
|
+
|
|
4104
|
+
|
|
4105
|
+
@pytest.mark.parametrize(
|
|
4106
|
+
("zone_id", "value", "message"),
|
|
4107
|
+
[
|
|
4108
|
+
pytest.param(1, 18.5, "target zone_id must match zone_id", id="zone_mismatch"),
|
|
4109
|
+
pytest.param(
|
|
4110
|
+
2,
|
|
4111
|
+
18.4,
|
|
4112
|
+
"value must align with increment relative to minimum",
|
|
4113
|
+
id="off_step",
|
|
4114
|
+
),
|
|
4115
|
+
pytest.param(
|
|
4116
|
+
2,
|
|
4117
|
+
22.5,
|
|
4118
|
+
"value must be between minimum and maximum",
|
|
4119
|
+
id="out_of_range",
|
|
4120
|
+
),
|
|
4121
|
+
],
|
|
4122
|
+
)
|
|
4123
|
+
async def test_set_bypass_supply_temperature_target_rejects_target_mismatch(
|
|
4124
|
+
zone_id: int,
|
|
4125
|
+
value: float,
|
|
4126
|
+
message: str,
|
|
4127
|
+
) -> None:
|
|
4128
|
+
"""Metadata-aware writes should reject invalid values before network I/O."""
|
|
4129
|
+
target = BypassSupplyTemperatureTarget(
|
|
4130
|
+
zone_id=2,
|
|
4131
|
+
value=18.5,
|
|
4132
|
+
minimum=12.0,
|
|
4133
|
+
increment=0.5,
|
|
4134
|
+
maximum=22.0,
|
|
4135
|
+
)
|
|
4136
|
+
|
|
4137
|
+
async with aiohttp.ClientSession() as session:
|
|
4138
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
4139
|
+
request = MagicMock()
|
|
4140
|
+
with (
|
|
4141
|
+
patch.object(session, "request", request),
|
|
4142
|
+
pytest.raises(ValueError, match=message),
|
|
4143
|
+
):
|
|
4144
|
+
await client.async_set_bypass_supply_temperature_target(
|
|
4145
|
+
zone_id,
|
|
4146
|
+
value,
|
|
4147
|
+
target=target,
|
|
4148
|
+
)
|
|
4149
|
+
|
|
4150
|
+
request.assert_not_called()
|
|
4151
|
+
|
|
4152
|
+
|
|
4153
|
+
async def test_set_bypass_supply_temperature_target_rejects_invalid_response() -> None:
|
|
4154
|
+
"""Bypass writes should reject incomplete target metadata in the response."""
|
|
4155
|
+
mock_response = _response(
|
|
4156
|
+
json_payload={
|
|
4157
|
+
"HeatRecovery": {"Bypass": {"TempSupTgtZone1": {"Val": 180, "Min": 120, "Inc": 5}}}
|
|
4158
|
+
}
|
|
4159
|
+
)
|
|
4160
|
+
|
|
4161
|
+
async with aiohttp.ClientSession() as session:
|
|
4162
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
4163
|
+
with (
|
|
4164
|
+
patch.object(session, "request", _request(mock_response)),
|
|
4165
|
+
pytest.raises(DucoError, match="Invalid TempSupTgtZone1: missing Max"),
|
|
4166
|
+
):
|
|
4167
|
+
await client.async_set_bypass_supply_temperature_target(1, 18.0)
|
|
4168
|
+
|
|
4169
|
+
|
|
3978
4170
|
@pytest.mark.parametrize(
|
|
3979
4171
|
("value", "message"),
|
|
3980
4172
|
[
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
4
|
import logging
|
|
5
|
+
from typing import Any, cast
|
|
5
6
|
|
|
6
7
|
import pytest
|
|
7
8
|
|
|
@@ -41,6 +42,8 @@ from duco_connectivity import (
|
|
|
41
42
|
ConfigZonesOverview,
|
|
42
43
|
ConfigZoneStruct,
|
|
43
44
|
DeviceGroupConfigSubmoduleSelector,
|
|
45
|
+
DiagComponent,
|
|
46
|
+
DiagStatus,
|
|
44
47
|
DucoSerialNumber,
|
|
45
48
|
DucoVersion,
|
|
46
49
|
HostName,
|
|
@@ -275,6 +278,87 @@ def test_selector_enum_values() -> None:
|
|
|
275
278
|
assert DeviceGroupConfigSubmoduleSelector.GENERAL.value == "General"
|
|
276
279
|
|
|
277
280
|
|
|
281
|
+
@pytest.mark.parametrize(
|
|
282
|
+
("raw_status", "expected_status"),
|
|
283
|
+
[
|
|
284
|
+
pytest.param("Ok", DiagStatus.OK, id="ok"),
|
|
285
|
+
pytest.param("Disable", DiagStatus.DISABLED, id="disabled"),
|
|
286
|
+
pytest.param("Error", DiagStatus.ERROR, id="error"),
|
|
287
|
+
pytest.param("FutureState", None, id="unknown"),
|
|
288
|
+
],
|
|
289
|
+
)
|
|
290
|
+
def test_diag_component_accepts_legacy_raw_status(
|
|
291
|
+
raw_status: str, expected_status: DiagStatus | None
|
|
292
|
+
) -> None:
|
|
293
|
+
"""DiagComponent should normalize status strings accepted before version 0.13."""
|
|
294
|
+
raw_payload = {"Status": raw_status}
|
|
295
|
+
|
|
296
|
+
component = DiagComponent(
|
|
297
|
+
component="Ventilation",
|
|
298
|
+
status=raw_status,
|
|
299
|
+
raw_payload=raw_payload,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
assert component.status is expected_status
|
|
303
|
+
assert component.raw_status == raw_status
|
|
304
|
+
assert component.raw_payload is raw_payload
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def test_diag_component_accepts_legacy_positional_raw_payload() -> None:
|
|
308
|
+
"""DiagComponent should retain the legacy positional raw payload argument."""
|
|
309
|
+
raw_payload = {"Status": "Ok"}
|
|
310
|
+
|
|
311
|
+
component = DiagComponent("Ventilation", "Ok", raw_payload)
|
|
312
|
+
|
|
313
|
+
assert component.status is DiagStatus.OK
|
|
314
|
+
assert component.raw_status == "Ok"
|
|
315
|
+
assert component.raw_payload is raw_payload
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def test_diag_component_accepts_normalized_status() -> None:
|
|
319
|
+
"""DiagComponent should retain the explicit normalized status contract."""
|
|
320
|
+
component = DiagComponent(
|
|
321
|
+
component="Ventilation",
|
|
322
|
+
status=DiagStatus.OK,
|
|
323
|
+
raw_status="Ok",
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
assert component.status is DiagStatus.OK
|
|
327
|
+
assert component.raw_status == "Ok"
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def test_diag_component_rejects_conflicting_legacy_raw_status() -> None:
|
|
331
|
+
"""DiagComponent should reject conflicting legacy raw status values."""
|
|
332
|
+
with pytest.raises(ValueError, match="raw_status must match status"):
|
|
333
|
+
DiagComponent(
|
|
334
|
+
component="Ventilation",
|
|
335
|
+
status="Ok",
|
|
336
|
+
raw_status="Error",
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def test_diag_component_accepts_matching_legacy_raw_status() -> None:
|
|
341
|
+
"""DiagComponent should accept matching explicit legacy raw status values."""
|
|
342
|
+
component = DiagComponent(
|
|
343
|
+
component="Ventilation",
|
|
344
|
+
status="Ok",
|
|
345
|
+
raw_status="Ok",
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
assert component.status is DiagStatus.OK
|
|
349
|
+
assert component.raw_status == "Ok"
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def test_diag_component_rejects_non_string_raw_status() -> None:
|
|
353
|
+
"""DiagComponent should reject non-string raw status values."""
|
|
354
|
+
with pytest.raises(TypeError, match="raw_status must be a string"):
|
|
355
|
+
DiagComponent(
|
|
356
|
+
component="Ventilation",
|
|
357
|
+
status=DiagStatus.OK,
|
|
358
|
+
raw_status=cast(str, 42),
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
|
|
278
362
|
def test_board_name_known_value() -> None:
|
|
279
363
|
"""BoardName should expose observed stable board identities."""
|
|
280
364
|
board_name = BoardName("SILENT_CONNECT")
|
|
@@ -688,6 +772,73 @@ def test_temperature_convenience_models_default_and_preserve_values() -> None:
|
|
|
688
772
|
assert target.maximum == 22.0
|
|
689
773
|
|
|
690
774
|
|
|
775
|
+
@pytest.fixture
|
|
776
|
+
def bypass_target() -> BypassSupplyTemperatureTarget:
|
|
777
|
+
"""Return a bypass target with a non-zero minimum and fractional step."""
|
|
778
|
+
return BypassSupplyTemperatureTarget(
|
|
779
|
+
zone_id=2,
|
|
780
|
+
value=18.5,
|
|
781
|
+
minimum=10.1,
|
|
782
|
+
increment=0.5,
|
|
783
|
+
maximum=25.4,
|
|
784
|
+
)
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
@pytest.mark.parametrize("value", [10.1, 18.6, 25.1])
|
|
788
|
+
def test_bypass_target_validates_supported_values(
|
|
789
|
+
bypass_target: BypassSupplyTemperatureTarget,
|
|
790
|
+
value: float,
|
|
791
|
+
) -> None:
|
|
792
|
+
"""Target validation should return supported Celsius values unchanged."""
|
|
793
|
+
assert bypass_target.validate_value(value) == value
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
@pytest.mark.parametrize(
|
|
797
|
+
("value", "message"),
|
|
798
|
+
[
|
|
799
|
+
pytest.param("18.6", "value must be an int or float, got str", id="nonnumeric"),
|
|
800
|
+
pytest.param(True, "value must be an int or float, got bool", id="boolean"),
|
|
801
|
+
pytest.param(float("inf"), "value must be finite", id="infinite"),
|
|
802
|
+
pytest.param(float("nan"), "value must be finite", id="nan"),
|
|
803
|
+
pytest.param(10.0, "value must be between minimum and maximum", id="below_minimum"),
|
|
804
|
+
pytest.param(25.5, "value must be between minimum and maximum", id="above_maximum"),
|
|
805
|
+
pytest.param(
|
|
806
|
+
18.5,
|
|
807
|
+
"value must align with increment relative to minimum",
|
|
808
|
+
id="off_step",
|
|
809
|
+
),
|
|
810
|
+
],
|
|
811
|
+
)
|
|
812
|
+
def test_bypass_target_rejects_invalid_values(
|
|
813
|
+
bypass_target: BypassSupplyTemperatureTarget,
|
|
814
|
+
value: object,
|
|
815
|
+
message: str,
|
|
816
|
+
) -> None:
|
|
817
|
+
"""Target validation should reject values outside its capability contract."""
|
|
818
|
+
with pytest.raises(ValueError, match=message):
|
|
819
|
+
bypass_target.validate_value(cast(Any, value))
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
@pytest.mark.parametrize(
|
|
823
|
+
("value", "expected"),
|
|
824
|
+
[
|
|
825
|
+
pytest.param(18.34, 18.1, id="round_down"),
|
|
826
|
+
pytest.param(18.35, 18.6, id="half_up"),
|
|
827
|
+
pytest.param(18.36, 18.6, id="round_up"),
|
|
828
|
+
pytest.param(9.9, 10.1, id="clamp_minimum"),
|
|
829
|
+
pytest.param(25.4, 25.1, id="clamp_highest_step_below_maximum"),
|
|
830
|
+
pytest.param(26.0, 25.1, id="clamp_above_maximum"),
|
|
831
|
+
],
|
|
832
|
+
)
|
|
833
|
+
def test_bypass_target_normalizes_values(
|
|
834
|
+
bypass_target: BypassSupplyTemperatureTarget,
|
|
835
|
+
value: float,
|
|
836
|
+
expected: float,
|
|
837
|
+
) -> None:
|
|
838
|
+
"""Target normalization should round and clamp using exact step arithmetic."""
|
|
839
|
+
assert bypass_target.normalize_value(value) == expected
|
|
840
|
+
|
|
841
|
+
|
|
691
842
|
def test_config_group_struct_defaults() -> None:
|
|
692
843
|
"""ConfigGroupStruct should preserve an empty raw payload by default."""
|
|
693
844
|
group = ConfigGroupStruct()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/cli.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/src/duco_connectivity/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.0 → python_duco_connectivity-0.14.0}/tests/test_replay_helpers.py
RENAMED
|
File without changes
|