python-duco-connectivity 0.13.1__tar.gz → 0.15.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.1/src/python_duco_connectivity.egg-info → python_duco_connectivity-0.15.0}/PKG-INFO +19 -11
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/README.md +18 -10
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/pyproject.toml +1 -1
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/client.py +52 -25
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/models.py +46 -3
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0/src/python_duco_connectivity.egg-info}/PKG-INFO +19 -11
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_api_reference.py +2 -1
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_client.py +204 -43
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_models.py +68 -1
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/LICENSE +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/setup.cfg +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/__init__.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/__main__.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/cli.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/exceptions.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/py.typed +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/python_duco_connectivity.egg-info/SOURCES.txt +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/python_duco_connectivity.egg-info/dependency_links.txt +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/python_duco_connectivity.egg-info/entry_points.txt +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/python_duco_connectivity.egg-info/requires.txt +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/python_duco_connectivity.egg-info/top_level.txt +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_cli.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_exceptions.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_local_sample_validation.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_pytest_live_support.py +0 -0
- {python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.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.15.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,21 +64,29 @@ 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.
|
|
82
90
|
|
|
83
91
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
84
92
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
|
@@ -32,21 +32,29 @@ 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.
|
|
50
58
|
|
|
51
59
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
52
60
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.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,14 @@ class DucoClient:
|
|
|
2356
2378
|
self,
|
|
2357
2379
|
zone_id: int,
|
|
2358
2380
|
temperature: float,
|
|
2381
|
+
*,
|
|
2382
|
+
target: BypassSupplyTemperatureTarget,
|
|
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.zone_id != zone_id:
|
|
2387
|
+
raise ValueError("target zone_id must match zone_id")
|
|
2388
|
+
target.validate_value(temperature)
|
|
2362
2389
|
raw_value = self._celsius_to_decicelsius(
|
|
2363
2390
|
temperature,
|
|
2364
2391
|
path=f"bypass_supply_temperature_target[{zone_id}]",
|
|
@@ -2369,11 +2396,11 @@ class DucoClient:
|
|
|
2369
2396
|
submodule=ConfigHeatRecoverySubmoduleSelector.BYPASS,
|
|
2370
2397
|
parameter=parameter,
|
|
2371
2398
|
)
|
|
2372
|
-
|
|
2373
|
-
if
|
|
2399
|
+
updated_target = self._extract_bypass_supply_temperature_target(response, zone_id)
|
|
2400
|
+
if updated_target is None:
|
|
2374
2401
|
msg = f"Expected {parameter} in /config response after bypass target write"
|
|
2375
2402
|
raise DucoError(msg)
|
|
2376
|
-
return
|
|
2403
|
+
return updated_target
|
|
2377
2404
|
|
|
2378
2405
|
async def async_get_write_req_remaining(self) -> int:
|
|
2379
2406
|
"""Backward-compatible alias for the old write budget method name."""
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.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:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-duco-connectivity
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.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,21 +64,29 @@ 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.
|
|
82
90
|
|
|
83
91
|
Diagnostic subsystem reads expose known status values as normalized `DiagStatus`
|
|
84
92
|
members (`ok`, `disabled`, or `error`). Each `DiagComponent` also keeps the exact
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.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:
|
|
@@ -3942,56 +4042,117 @@ async def test_bypass_supply_temperature_helpers_reject_invalid_zone_ids(zone_id
|
|
|
3942
4042
|
with pytest.raises(ValueError, match="zone_id must be an integer between 1 and 8"):
|
|
3943
4043
|
await client.async_get_bypass_supply_temperature_target(cast(Any, zone_id))
|
|
3944
4044
|
|
|
4045
|
+
dummy_target = BypassSupplyTemperatureTarget(
|
|
4046
|
+
zone_id=1, value=18.0, minimum=12.0, increment=0.5, maximum=22.0
|
|
4047
|
+
)
|
|
3945
4048
|
with pytest.raises(ValueError, match="zone_id must be an integer between 1 and 8"):
|
|
3946
|
-
await client.async_set_bypass_supply_temperature_target(
|
|
4049
|
+
await client.async_set_bypass_supply_temperature_target(
|
|
4050
|
+
cast(Any, zone_id), 18.0, target=dummy_target
|
|
4051
|
+
)
|
|
3947
4052
|
|
|
3948
4053
|
|
|
3949
|
-
async def
|
|
4054
|
+
async def test_set_bypass_supply_temperature_target_validates_against_target(
|
|
3950
4055
|
config_data: dict[str, object],
|
|
3951
4056
|
) -> None:
|
|
3952
|
-
"""
|
|
4057
|
+
"""Metadata-aware writes should validate and issue one PATCH without a GET."""
|
|
4058
|
+
target = BypassSupplyTemperatureTarget(
|
|
4059
|
+
zone_id=2,
|
|
4060
|
+
value=18.5,
|
|
4061
|
+
minimum=12.0,
|
|
4062
|
+
increment=0.5,
|
|
4063
|
+
maximum=22.0,
|
|
4064
|
+
)
|
|
3953
4065
|
mock_response = _response(json_payload=config_data)
|
|
3954
4066
|
|
|
3955
4067
|
async with aiohttp.ClientSession() as session:
|
|
3956
4068
|
client = DucoClient(session=session, host="192.0.2.94")
|
|
3957
4069
|
request = MagicMock(return_value=_request_context(mock_response))
|
|
3958
4070
|
with patch.object(session, "request", request):
|
|
3959
|
-
|
|
4071
|
+
await client.async_set_bypass_supply_temperature_target(
|
|
4072
|
+
2,
|
|
4073
|
+
18.5,
|
|
4074
|
+
target=target,
|
|
4075
|
+
)
|
|
3960
4076
|
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
value=18.5,
|
|
3964
|
-
minimum=12.0,
|
|
3965
|
-
increment=0.5,
|
|
3966
|
-
maximum=22.0,
|
|
3967
|
-
)
|
|
3968
|
-
_, kwargs = request.call_args
|
|
3969
|
-
assert kwargs["params"] == {
|
|
3970
|
-
"module": "HeatRecovery",
|
|
3971
|
-
"submodule": "Bypass",
|
|
3972
|
-
"parameter": "TempSupTgtZone2",
|
|
3973
|
-
}
|
|
3974
|
-
assert kwargs["data"] == b'{"HeatRecovery":{"Bypass":{"TempSupTgtZone2":{"Val":185}}}}'
|
|
3975
|
-
assert kwargs["headers"] == {"Content-Type": "application/json"}
|
|
4077
|
+
request.assert_called_once()
|
|
4078
|
+
assert request.call_args.args[:2] == ("PATCH", "http://192.0.2.94/config")
|
|
3976
4079
|
|
|
3977
4080
|
|
|
3978
4081
|
@pytest.mark.parametrize(
|
|
3979
|
-
("value", "message"),
|
|
4082
|
+
("zone_id", "value", "message"),
|
|
3980
4083
|
[
|
|
3981
|
-
pytest.param(18.
|
|
3982
|
-
pytest.param(
|
|
3983
|
-
|
|
4084
|
+
pytest.param(1, 18.5, "target zone_id must match zone_id", id="zone_mismatch"),
|
|
4085
|
+
pytest.param(
|
|
4086
|
+
2,
|
|
4087
|
+
18.4,
|
|
4088
|
+
"value must align with increment relative to minimum",
|
|
4089
|
+
id="off_step",
|
|
4090
|
+
),
|
|
4091
|
+
pytest.param(
|
|
4092
|
+
2,
|
|
4093
|
+
22.5,
|
|
4094
|
+
"value must be between minimum and maximum",
|
|
4095
|
+
id="out_of_range",
|
|
4096
|
+
),
|
|
3984
4097
|
],
|
|
3985
4098
|
)
|
|
3986
|
-
async def
|
|
3987
|
-
|
|
4099
|
+
async def test_set_bypass_supply_temperature_target_rejects_target_mismatch(
|
|
4100
|
+
zone_id: int,
|
|
4101
|
+
value: float,
|
|
3988
4102
|
message: str,
|
|
3989
4103
|
) -> None:
|
|
3990
|
-
"""
|
|
4104
|
+
"""Metadata-aware writes should reject invalid values before network I/O."""
|
|
4105
|
+
target = BypassSupplyTemperatureTarget(
|
|
4106
|
+
zone_id=2,
|
|
4107
|
+
value=18.5,
|
|
4108
|
+
minimum=12.0,
|
|
4109
|
+
increment=0.5,
|
|
4110
|
+
maximum=22.0,
|
|
4111
|
+
)
|
|
4112
|
+
|
|
3991
4113
|
async with aiohttp.ClientSession() as session:
|
|
3992
4114
|
client = DucoClient(session=session, host="192.0.2.94")
|
|
3993
|
-
|
|
3994
|
-
|
|
4115
|
+
request = MagicMock()
|
|
4116
|
+
with (
|
|
4117
|
+
patch.object(session, "request", request),
|
|
4118
|
+
pytest.raises(ValueError, match=message),
|
|
4119
|
+
):
|
|
4120
|
+
await client.async_set_bypass_supply_temperature_target(
|
|
4121
|
+
zone_id,
|
|
4122
|
+
value,
|
|
4123
|
+
target=target,
|
|
4124
|
+
)
|
|
4125
|
+
|
|
4126
|
+
request.assert_not_called()
|
|
4127
|
+
|
|
4128
|
+
|
|
4129
|
+
async def test_set_bypass_supply_temperature_target_rejects_invalid_response() -> None:
|
|
4130
|
+
"""Bypass writes should reject incomplete target metadata in the response."""
|
|
4131
|
+
mock_response = _response(
|
|
4132
|
+
json_payload={
|
|
4133
|
+
"HeatRecovery": {"Bypass": {"TempSupTgtZone1": {"Val": 180, "Min": 120, "Inc": 5}}}
|
|
4134
|
+
}
|
|
4135
|
+
)
|
|
4136
|
+
|
|
4137
|
+
async with aiohttp.ClientSession() as session:
|
|
4138
|
+
client = DucoClient(session=session, host="192.0.2.94")
|
|
4139
|
+
valid_target = BypassSupplyTemperatureTarget(
|
|
4140
|
+
zone_id=1, value=18.0, minimum=12.0, increment=0.5, maximum=22.0
|
|
4141
|
+
)
|
|
4142
|
+
mock_request = _request(mock_response)
|
|
4143
|
+
with (
|
|
4144
|
+
patch.object(session, "request", mock_request),
|
|
4145
|
+
pytest.raises(DucoError, match="Invalid TempSupTgtZone1: missing Max"),
|
|
4146
|
+
):
|
|
4147
|
+
await client.async_set_bypass_supply_temperature_target(1, 18.0, target=valid_target)
|
|
4148
|
+
|
|
4149
|
+
_, kwargs = mock_request.call_args
|
|
4150
|
+
assert kwargs["params"] == {
|
|
4151
|
+
"module": "HeatRecovery",
|
|
4152
|
+
"submodule": "Bypass",
|
|
4153
|
+
"parameter": "TempSupTgtZone1",
|
|
4154
|
+
}
|
|
4155
|
+
assert kwargs["data"] == b'{"HeatRecovery":{"Bypass":{"TempSupTgtZone1":{"Val":180}}}}'
|
|
3995
4156
|
|
|
3996
4157
|
|
|
3997
4158
|
async def test_get_write_requests_remaining_is_parsed() -> None:
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
4
|
import logging
|
|
5
|
-
from typing import cast
|
|
5
|
+
from typing import Any, cast
|
|
6
6
|
|
|
7
7
|
import pytest
|
|
8
8
|
|
|
@@ -772,6 +772,73 @@ def test_temperature_convenience_models_default_and_preserve_values() -> None:
|
|
|
772
772
|
assert target.maximum == 22.0
|
|
773
773
|
|
|
774
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
|
+
|
|
775
842
|
def test_config_group_struct_defaults() -> None:
|
|
776
843
|
"""ConfigGroupStruct should preserve an empty raw payload by default."""
|
|
777
844
|
group = ConfigGroupStruct()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/src/duco_connectivity/cli.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.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.1 → python_duco_connectivity-0.15.0}/tests/test_exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_duco_connectivity-0.13.1 → python_duco_connectivity-0.15.0}/tests/test_replay_helpers.py
RENAMED
|
File without changes
|