aiowinet 0.1.0__py3-none-any.whl
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.
- aiowinet/__init__.py +71 -0
- aiowinet/_profile.py +80 -0
- aiowinet/_register.py +69 -0
- aiowinet/client.py +617 -0
- aiowinet/const.py +9 -0
- aiowinet/dialects/__init__.py +38 -0
- aiowinet/dialects/base.py +42 -0
- aiowinet/dialects/params.py +241 -0
- aiowinet/dialects/ram_eep.py +167 -0
- aiowinet/dialects/registers.py +249 -0
- aiowinet/dialects/rest_api.py +23 -0
- aiowinet/discovery.py +142 -0
- aiowinet/exceptions.py +41 -0
- aiowinet/models.py +213 -0
- aiowinet/py.typed +0 -0
- aiowinet/registers.py +72 -0
- aiowinet/testing.py +393 -0
- aiowinet-0.1.0.dist-info/METADATA +241 -0
- aiowinet-0.1.0.dist-info/RECORD +21 -0
- aiowinet-0.1.0.dist-info/WHEEL +4 -0
- aiowinet-0.1.0.dist-info/licenses/LICENSE +21 -0
aiowinet/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Async pellet stove register client."""
|
|
2
|
+
|
|
3
|
+
from ._profile import PowerSwitch, Profile
|
|
4
|
+
from .client import DEFAULT_POWER_GUARD, PelletStove
|
|
5
|
+
from .dialects import PROFILES
|
|
6
|
+
from .discovery import (
|
|
7
|
+
DISCOVERY_PORT,
|
|
8
|
+
DiscoveredModule,
|
|
9
|
+
async_discover,
|
|
10
|
+
async_get_module_id,
|
|
11
|
+
)
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
PelletStoveConnectionError,
|
|
14
|
+
PelletStoveError,
|
|
15
|
+
PelletStovePowerOutcomeUnknownError,
|
|
16
|
+
PelletStoveReadOnlyError,
|
|
17
|
+
PelletStoveRejectedError,
|
|
18
|
+
PelletStoveResponseError,
|
|
19
|
+
PelletStoveUnsupportedDialectError,
|
|
20
|
+
PelletStoveUnsupportedError,
|
|
21
|
+
PelletStoveValueError,
|
|
22
|
+
)
|
|
23
|
+
from .models import (
|
|
24
|
+
ALARM_STATES,
|
|
25
|
+
BLOCKED_ACTIVITIES,
|
|
26
|
+
TOGGLE_BLOCKED_STATES,
|
|
27
|
+
Activity,
|
|
28
|
+
FanRegulation,
|
|
29
|
+
ModuleInfo,
|
|
30
|
+
PowerCommandOutcome,
|
|
31
|
+
PowerResult,
|
|
32
|
+
PowerState,
|
|
33
|
+
StoveAlarm,
|
|
34
|
+
StoveState,
|
|
35
|
+
StoveStatus,
|
|
36
|
+
)
|
|
37
|
+
from .registers import Register
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"ALARM_STATES",
|
|
41
|
+
"BLOCKED_ACTIVITIES",
|
|
42
|
+
"DEFAULT_POWER_GUARD",
|
|
43
|
+
"DISCOVERY_PORT",
|
|
44
|
+
"PROFILES",
|
|
45
|
+
"TOGGLE_BLOCKED_STATES",
|
|
46
|
+
"Activity",
|
|
47
|
+
"DiscoveredModule",
|
|
48
|
+
"FanRegulation",
|
|
49
|
+
"ModuleInfo",
|
|
50
|
+
"PelletStove",
|
|
51
|
+
"PelletStoveConnectionError",
|
|
52
|
+
"PelletStoveError",
|
|
53
|
+
"PelletStovePowerOutcomeUnknownError",
|
|
54
|
+
"PelletStoveReadOnlyError",
|
|
55
|
+
"PelletStoveRejectedError",
|
|
56
|
+
"PelletStoveResponseError",
|
|
57
|
+
"PelletStoveUnsupportedDialectError",
|
|
58
|
+
"PelletStoveUnsupportedError",
|
|
59
|
+
"PelletStoveValueError",
|
|
60
|
+
"PowerCommandOutcome",
|
|
61
|
+
"PowerResult",
|
|
62
|
+
"PowerState",
|
|
63
|
+
"PowerSwitch",
|
|
64
|
+
"Profile",
|
|
65
|
+
"Register",
|
|
66
|
+
"StoveAlarm",
|
|
67
|
+
"StoveState",
|
|
68
|
+
"StoveStatus",
|
|
69
|
+
"async_discover",
|
|
70
|
+
"async_get_module_id",
|
|
71
|
+
]
|
aiowinet/_profile.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Stove profiles: what the registers of one kind of stove board mean."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
|
+
|
|
6
|
+
from ._register import Register
|
|
7
|
+
from .const import API_KEY_TOGGLE_POWER
|
|
8
|
+
from .models import StoveAlarm, StoveStatus
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class PowerSwitch:
|
|
13
|
+
"""An absolute on/off command: a register written with an on or off value."""
|
|
14
|
+
|
|
15
|
+
register: Register
|
|
16
|
+
on: int
|
|
17
|
+
off: int
|
|
18
|
+
# Turning off also clears an alarm (the stove's panel does the same).
|
|
19
|
+
off_clears_alarm: bool = False
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class Profile:
|
|
24
|
+
"""The register map of one kind of stove board, as data.
|
|
25
|
+
|
|
26
|
+
A dialect is the shape of the module's answers; a profile says what the
|
|
27
|
+
registers mean within that dialect: which register holds what, at which
|
|
28
|
+
scale, which status table and which alarms apply. Several profiles can
|
|
29
|
+
share a dialect. Applications may build their own profile to try a stove
|
|
30
|
+
the library does not know yet, then propose it upstream.
|
|
31
|
+
|
|
32
|
+
Registers are named after the ``StoveState`` fields they fill; a field
|
|
33
|
+
with no register is ``None`` in the state.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
name: str
|
|
37
|
+
# Name of the dialect whose answers this profile reads.
|
|
38
|
+
dialect: str
|
|
39
|
+
status: type[StoveStatus]
|
|
40
|
+
power_state: Register
|
|
41
|
+
target_temperature: Register
|
|
42
|
+
power_level: Register
|
|
43
|
+
# Registers read by ``async_get_state``, in reading order.
|
|
44
|
+
state_registers: tuple[Register, ...]
|
|
45
|
+
# Slow counters, read only when diagnostics are requested.
|
|
46
|
+
diagnostic_registers: tuple[Register, ...] = ()
|
|
47
|
+
room_fan: Register | None = None
|
|
48
|
+
fan_level: Register | None = None
|
|
49
|
+
# Register holding alarm bits, and the alarm of each bit, lowest first.
|
|
50
|
+
alarm_bits: Register | None = None
|
|
51
|
+
alarm_names: tuple[StoveAlarm, ...] = ()
|
|
52
|
+
# Alarm bits mean something in every status (otherwise only in alarms).
|
|
53
|
+
alarms_in_every_status: bool = False
|
|
54
|
+
# Absolute on/off command, for boards that have one instead of the toggle.
|
|
55
|
+
power_switch: PowerSwitch | None = None
|
|
56
|
+
# The power toggle request, or None when the board has no toggle.
|
|
57
|
+
power_toggle_request: Mapping[str, str] | None = field(
|
|
58
|
+
default_factory=lambda: {"key": API_KEY_TOGGLE_POWER}, compare=False
|
|
59
|
+
)
|
|
60
|
+
# Request that clears an alarm (the stove then shuts down), if known.
|
|
61
|
+
alarm_clear_request: Mapping[str, str] | None = field(default=None, compare=False)
|
|
62
|
+
# Where the map comes from, and on which hardware it was verified, if any.
|
|
63
|
+
source: str = ""
|
|
64
|
+
verified_on: str = ""
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def experimental(self) -> bool:
|
|
68
|
+
"""True while no real stove has confirmed the map."""
|
|
69
|
+
return not self.verified_on
|
|
70
|
+
|
|
71
|
+
def decode_alarms(self, status: StoveStatus, bits: int) -> frozenset[StoveAlarm]:
|
|
72
|
+
"""Alarms set in the alarm register; it means nothing outside alarms."""
|
|
73
|
+
if not (status.is_alarm or self.alarms_in_every_status):
|
|
74
|
+
return frozenset()
|
|
75
|
+
names = self.alarm_names
|
|
76
|
+
return frozenset(
|
|
77
|
+
names[bit] if bit < len(names) else StoveAlarm.UNKNOWN
|
|
78
|
+
for bit in range(bits.bit_length())
|
|
79
|
+
if bits & (1 << bit)
|
|
80
|
+
)
|
aiowinet/_register.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Dialect-independent register description and pure encoding helpers."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from .exceptions import (
|
|
9
|
+
PelletStoveReadOnlyError,
|
|
10
|
+
PelletStoveResponseError,
|
|
11
|
+
PelletStoveValueError,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
Value = int | float | bool
|
|
15
|
+
Memory = Literal["ram", "eep", "param", "register"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class Register:
|
|
20
|
+
name: str
|
|
21
|
+
memory: Memory
|
|
22
|
+
reg_id: int
|
|
23
|
+
category: int = 2
|
|
24
|
+
fmt: type[int] | type[float] | type[bool] = int
|
|
25
|
+
read_only: bool = False
|
|
26
|
+
minimum: int | None = None
|
|
27
|
+
maximum: int | None = None
|
|
28
|
+
scale: float = 1.0
|
|
29
|
+
offset: int = 0
|
|
30
|
+
high_byte_reg_id: int | None = None
|
|
31
|
+
# Bits of the raw value that hold this register's value (read-only use).
|
|
32
|
+
mask: int | None = None
|
|
33
|
+
# Extra check on the raw value to write, for packed registers.
|
|
34
|
+
raw_check: Callable[[int], bool] | None = field(default=None, compare=False)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def decode(reg: Register, raw: int) -> Value:
|
|
38
|
+
if reg.mask is not None:
|
|
39
|
+
raw &= reg.mask
|
|
40
|
+
if reg.fmt is bool:
|
|
41
|
+
return bool(raw)
|
|
42
|
+
value = raw * reg.scale + reg.offset
|
|
43
|
+
return round(value, 1) if reg.fmt is float else int(value)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def encode(reg: Register, value: Value) -> int:
|
|
47
|
+
if reg.read_only:
|
|
48
|
+
raise PelletStoveReadOnlyError(f"{reg.name} is read-only")
|
|
49
|
+
if not isinstance(value, (int, float)) or not math.isfinite(value):
|
|
50
|
+
raise PelletStoveValueError(f"Invalid value for {reg.name}")
|
|
51
|
+
if reg.minimum is not None and value < reg.minimum:
|
|
52
|
+
raise PelletStoveValueError(f"{reg.name} minimum is {reg.minimum}")
|
|
53
|
+
if reg.maximum is not None and value > reg.maximum:
|
|
54
|
+
raise PelletStoveValueError(f"{reg.name} maximum is {reg.maximum}")
|
|
55
|
+
if reg.fmt is bool and value not in (0, 1):
|
|
56
|
+
raise PelletStoveValueError(f"{reg.name} requires a boolean")
|
|
57
|
+
raw = (value - reg.offset) / reg.scale
|
|
58
|
+
if not raw.is_integer() or not 0 <= raw <= 255:
|
|
59
|
+
raise PelletStoveValueError(f"Value cannot be encoded for {reg.name}")
|
|
60
|
+
result = int(raw)
|
|
61
|
+
if reg.raw_check is not None and not reg.raw_check(result):
|
|
62
|
+
raise PelletStoveValueError(f"Invalid packed value for {reg.name}")
|
|
63
|
+
return result
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def combine_bytes(low: int, high: int) -> int:
|
|
67
|
+
if not (0 <= low <= 255 and 0 <= high <= 255):
|
|
68
|
+
raise PelletStoveResponseError("Invalid counter byte")
|
|
69
|
+
return (high << 8) | low
|