PyPlumIO 0.7.1__tar.gz → 0.7.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.
- {pyplumio-0.7.1 → pyplumio-0.7.2}/PKG-INFO +1 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/data_types.py +1 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/devices/__init__.py +9 -5
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/frames/__init__.py +23 -9
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/frames/messages.py +2 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/frames/responses.py +21 -18
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/__init__.py +1 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/custom/__init__.py +2 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/stream.py +8 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/ecomax_extended_parameters.py +4 -13
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyproject.toml +1 -1
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/test_ecomax.py +21 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/test_init.py +16 -2
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/frames/test_init.py +31 -6
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/test_init.py +1 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_stream.py +28 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/.gitignore +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/LICENSE +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/README.md +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/Makefile +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/make.bat +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/callbacks.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/conf.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/connecting.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/frames.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/index.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/mixers_thermostats.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/protocol.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/reading.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/schedules.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/docs/source/writing.rst +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/__main__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/connection.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/const.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/devices/ecomax.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/devices/ecoster.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/devices/mixer.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/devices/thermostat.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/exceptions.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/filters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/frames/requests.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/helpers/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/helpers/async_cache.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/helpers/event_manager.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/helpers/task_manager.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/custom/ecomax_860d3_hb.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/ecomax.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/mixer.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/parameters/thermostat.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/protocol.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/py.typed +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/alerts.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/ecomax_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/frame_versions.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/mixer_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/network_info.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/product_info.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/program_version.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/regulator_data.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/regulator_data_schema.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/schedules.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/sensor_data.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/structures/thermostat_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/pyplumio/utils.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/conftest.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/test_ecoster.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/test_mixer.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/devices/test_thermostat.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/frames/test_messages.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/frames/test_requests.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/frames/test_responses.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/helpers/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/helpers/test_async_cache.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/helpers/test_event_manager.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/helpers/test_task_manager.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/helpers/test_uid.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/custom/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/custom/test_ecomax_860d3_hb.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/custom/test_init.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/test_ecomax.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/test_mixers.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/parameters/test_thermostats.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/ruff.toml +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/__init__.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_alerts.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_ecomax_extended_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_ecomax_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_frame_versions.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_mixer_parameters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_product_info.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_program_version.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/structures/test_schedules.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_connection.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_data_types.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_filters.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_init.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_main.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_protocol.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/test_utils.py +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/messages/regulator_data.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/messages/sensor_data.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/parameters/ecomax_860d3_hb.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/alerts.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/ecomax_control.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/ecomax_extended_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/ecomax_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/mixer_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_ecomax_extended_parameter.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_ecomax_parameter.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_mixer_parameter.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_schedule.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_thermostat_parameter.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/thermostat_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/alerts.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/device_available.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/ecomax_extended_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/ecomax_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/mixer_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/password.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/program_version.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/regulator_data_schema.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/schedules.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/thermostat_parameters.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/responses/uid.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/unknown/unknown_ecomax_parameter.json +0 -0
- {pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/unknown/unknown_mixer_parameter.json +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: PyPlumIO
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: PyPlumIO is a native ecoNET library for Plum ecoMAX controllers.
|
|
5
5
|
Project-URL: Documentation, https://pyplumio.denpa.pro
|
|
6
6
|
Project-URL: Source Code, https://github.com/denpamusic/PyPlumIO
|
|
@@ -15,6 +15,7 @@ from pyplumio.filters import on_change
|
|
|
15
15
|
from pyplumio.frames import Frame, Request, is_known_frame_type
|
|
16
16
|
from pyplumio.helpers.event_manager import EventManager, event_listener
|
|
17
17
|
from pyplumio.parameters import Numeric, Parameter
|
|
18
|
+
from pyplumio.structures.frame_versions import ATTR_FRAME_VERSIONS
|
|
18
19
|
from pyplumio.structures.network_info import NetworkInfo
|
|
19
20
|
from pyplumio.utils import create_instance, to_camelcase
|
|
20
21
|
|
|
@@ -133,7 +134,7 @@ class PhysicalDevice(Device, ABC):
|
|
|
133
134
|
logical devices associated with them via parent property.
|
|
134
135
|
"""
|
|
135
136
|
|
|
136
|
-
__slots__ = ("
|
|
137
|
+
__slots__ = ("_network_info", "_frame_versions")
|
|
137
138
|
|
|
138
139
|
address: ClassVar[int]
|
|
139
140
|
|
|
@@ -149,7 +150,7 @@ class PhysicalDevice(Device, ABC):
|
|
|
149
150
|
self._frame_versions = {}
|
|
150
151
|
|
|
151
152
|
@event_listener(filter=on_change)
|
|
152
|
-
async def on_event_frame_versions(self, versions: dict[int, int]) ->
|
|
153
|
+
async def on_event_frame_versions(self, versions: dict[int, int]) -> dict[int, int]:
|
|
153
154
|
"""Check frame versions and update outdated frames."""
|
|
154
155
|
_LOGGER.debug("Received frame version table")
|
|
155
156
|
for frame_type, version in versions.items():
|
|
@@ -166,6 +167,8 @@ class PhysicalDevice(Device, ABC):
|
|
|
166
167
|
await self._request_frame_version(request_frame_type, version)
|
|
167
168
|
self._frame_versions[frame_type] = version
|
|
168
169
|
|
|
170
|
+
return self.get_nowait(ATTR_FRAME_VERSIONS, {}) | versions
|
|
171
|
+
|
|
169
172
|
async def _request_frame_version(
|
|
170
173
|
self, frame_type: FrameType | int, version: int
|
|
171
174
|
) -> None:
|
|
@@ -188,9 +191,10 @@ class PhysicalDevice(Device, ABC):
|
|
|
188
191
|
def handle_frame(self, frame: Frame) -> None:
|
|
189
192
|
"""Handle frame received from the device."""
|
|
190
193
|
frame.assign_to(self)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
data = frame.data
|
|
195
|
+
_LOGGER.debug("Decoded frame: %s", frame)
|
|
196
|
+
for name, value in data.items():
|
|
197
|
+
self.dispatch_nowait(name, value)
|
|
194
198
|
|
|
195
199
|
async def request(
|
|
196
200
|
self, name: str, frame_type: FrameType, retries: int = 3, timeout: float = 3.0
|
|
@@ -9,7 +9,7 @@ import struct
|
|
|
9
9
|
from typing import TYPE_CHECKING, Any, ClassVar, Final, TypeVar
|
|
10
10
|
|
|
11
11
|
from pyplumio.const import DeviceType, FrameType
|
|
12
|
-
from pyplumio.exceptions import UnknownFrameError
|
|
12
|
+
from pyplumio.exceptions import FrameDataError, UnknownFrameError
|
|
13
13
|
from pyplumio.utils import create_instance, to_camelcase
|
|
14
14
|
|
|
15
15
|
if TYPE_CHECKING:
|
|
@@ -160,10 +160,17 @@ class Frame(ABC):
|
|
|
160
160
|
|
|
161
161
|
@property
|
|
162
162
|
def data(self) -> dict[str, Any]:
|
|
163
|
-
"""Return the frame data.
|
|
163
|
+
"""Return the frame data.
|
|
164
|
+
|
|
165
|
+
:return: Decoded frame data
|
|
166
|
+
:rtype: dict[str, Any]
|
|
167
|
+
:raise FrameDataError: when frame message can't be decoded
|
|
168
|
+
"""
|
|
164
169
|
if self._data is None:
|
|
165
170
|
self._data = (
|
|
166
|
-
self.
|
|
171
|
+
self._decode_message_safe(self._message)
|
|
172
|
+
if self._message is not None
|
|
173
|
+
else {}
|
|
167
174
|
)
|
|
168
175
|
|
|
169
176
|
return self._data
|
|
@@ -174,6 +181,18 @@ class Frame(ABC):
|
|
|
174
181
|
self._data = data
|
|
175
182
|
self._message = None
|
|
176
183
|
|
|
184
|
+
def _decode_message_safe(self, message: bytes) -> dict[str, Any]:
|
|
185
|
+
"""Decode a frame message and wrap decoding errors."""
|
|
186
|
+
try:
|
|
187
|
+
return self.decode_message(message)
|
|
188
|
+
except (struct.error, IndexError, UnicodeDecodeError) as e:
|
|
189
|
+
raise FrameDataError(
|
|
190
|
+
f"Failed to decode {self.__class__.__name__} "
|
|
191
|
+
f"(econet_type={self.econet_type}, "
|
|
192
|
+
f"econet_version={self.econet_version}): {e}. "
|
|
193
|
+
f"Message: {message.hex()}"
|
|
194
|
+
) from e
|
|
195
|
+
|
|
177
196
|
@property
|
|
178
197
|
def message(self) -> bytes:
|
|
179
198
|
"""Return the frame message."""
|
|
@@ -243,17 +262,12 @@ class Frame(ABC):
|
|
|
243
262
|
"""Decode a frame message."""
|
|
244
263
|
|
|
245
264
|
|
|
246
|
-
def frame_handler(
|
|
247
|
-
frame_type: FrameType, contains: type[Structure] | None = None
|
|
248
|
-
) -> Callable[[type[_FrameT]], type[_FrameT]]:
|
|
265
|
+
def frame_handler(frame_type: FrameType) -> Callable[[type[_FrameT]], type[_FrameT]]:
|
|
249
266
|
"""Specify frame type for the frame class."""
|
|
250
267
|
|
|
251
268
|
def wrapper(cls: type[_FrameT]) -> type[_FrameT]:
|
|
252
269
|
"""Wrap the frame class."""
|
|
253
270
|
setattr(cls, "frame_type", frame_type)
|
|
254
|
-
if contains and issubclass(cls, Response):
|
|
255
|
-
setattr(cls, "structures", (contains,))
|
|
256
|
-
|
|
257
271
|
return cls
|
|
258
272
|
|
|
259
273
|
return wrapper
|
|
@@ -9,7 +9,8 @@ from pyplumio.structures.regulator_data import RegulatorDataStructure
|
|
|
9
9
|
from pyplumio.structures.sensor_data import SensorDataStructure
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
@frame_handler(FrameType.MESSAGE_REGULATOR_DATA
|
|
12
|
+
@frame_handler(FrameType.MESSAGE_REGULATOR_DATA)
|
|
13
|
+
@contains(RegulatorDataStructure)
|
|
13
14
|
class RegulatorDataMessage(Message):
|
|
14
15
|
"""Represents a regulator data message."""
|
|
15
16
|
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
7
|
from pyplumio.const import ATTR_PASSWORD, FrameType
|
|
8
|
-
from pyplumio.frames import Response, frame_handler
|
|
8
|
+
from pyplumio.frames import Response, contains, frame_handler
|
|
9
9
|
from pyplumio.structures.alerts import AlertsStructure
|
|
10
10
|
from pyplumio.structures.ecomax_extended_parameters import (
|
|
11
11
|
EcomaxExtendedParametersStructure,
|
|
@@ -20,14 +20,16 @@ from pyplumio.structures.schedules import SchedulesStructure
|
|
|
20
20
|
from pyplumio.structures.thermostat_parameters import ThermostatParametersStructure
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
@frame_handler(FrameType.RESPONSE_ALERTS
|
|
23
|
+
@frame_handler(FrameType.RESPONSE_ALERTS)
|
|
24
|
+
@contains(AlertsStructure)
|
|
24
25
|
class AlertsResponse(Response):
|
|
25
26
|
"""Represents response to a device alerts request."""
|
|
26
27
|
|
|
27
28
|
__slots__ = ()
|
|
28
29
|
|
|
29
30
|
|
|
30
|
-
@frame_handler(FrameType.RESPONSE_DEVICE_AVAILABLE
|
|
31
|
+
@frame_handler(FrameType.RESPONSE_DEVICE_AVAILABLE)
|
|
32
|
+
@contains(NetworkInfoStructure)
|
|
31
33
|
class DeviceAvailableResponse(Response):
|
|
32
34
|
"""Represents a device available response.
|
|
33
35
|
|
|
@@ -48,10 +50,8 @@ class EcomaxControlResponse(Response):
|
|
|
48
50
|
__slots__ = ()
|
|
49
51
|
|
|
50
52
|
|
|
51
|
-
@frame_handler(
|
|
52
|
-
|
|
53
|
-
contains=EcomaxExtendedParametersStructure,
|
|
54
|
-
)
|
|
53
|
+
@frame_handler(FrameType.RESPONSE_ECOMAX_EXTENDED_PARAMETERS)
|
|
54
|
+
@contains(EcomaxExtendedParametersStructure)
|
|
55
55
|
class EcomaxExtendedParametersResponse(Response):
|
|
56
56
|
"""Represents an ecoMAX extended parameters response.
|
|
57
57
|
|
|
@@ -63,7 +63,8 @@ class EcomaxExtendedParametersResponse(Response):
|
|
|
63
63
|
__slots__ = ()
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
@frame_handler(FrameType.RESPONSE_ECOMAX_PARAMETERS
|
|
66
|
+
@frame_handler(FrameType.RESPONSE_ECOMAX_PARAMETERS)
|
|
67
|
+
@contains(EcomaxParametersStructure)
|
|
67
68
|
class EcomaxParametersResponse(Response):
|
|
68
69
|
"""Represents an ecoMAX parameters response.
|
|
69
70
|
|
|
@@ -73,7 +74,8 @@ class EcomaxParametersResponse(Response):
|
|
|
73
74
|
__slots__ = ()
|
|
74
75
|
|
|
75
76
|
|
|
76
|
-
@frame_handler(FrameType.RESPONSE_MIXER_PARAMETERS
|
|
77
|
+
@frame_handler(FrameType.RESPONSE_MIXER_PARAMETERS)
|
|
78
|
+
@contains(MixerParametersStructure)
|
|
77
79
|
class MixerParametersResponse(Response):
|
|
78
80
|
"""Represents a mixer parameters response.
|
|
79
81
|
|
|
@@ -98,7 +100,8 @@ class PasswordResponse(Response):
|
|
|
98
100
|
return {ATTR_PASSWORD: password}
|
|
99
101
|
|
|
100
102
|
|
|
101
|
-
@frame_handler(FrameType.RESPONSE_PROGRAM_VERSION
|
|
103
|
+
@frame_handler(FrameType.RESPONSE_PROGRAM_VERSION)
|
|
104
|
+
@contains(ProgramVersionStructure)
|
|
102
105
|
class ProgramVersionResponse(Response):
|
|
103
106
|
"""Represents a program version response.
|
|
104
107
|
|
|
@@ -108,9 +111,8 @@ class ProgramVersionResponse(Response):
|
|
|
108
111
|
__slots__ = ()
|
|
109
112
|
|
|
110
113
|
|
|
111
|
-
@frame_handler(
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
+
@frame_handler(FrameType.RESPONSE_REGULATOR_DATA_SCHEMA)
|
|
115
|
+
@contains(RegulatorDataSchemaStructure)
|
|
114
116
|
class RegulatorDataSchemaResponse(Response):
|
|
115
117
|
"""Represents a regulator data schema response.
|
|
116
118
|
|
|
@@ -121,7 +123,8 @@ class RegulatorDataSchemaResponse(Response):
|
|
|
121
123
|
__slots__ = ()
|
|
122
124
|
|
|
123
125
|
|
|
124
|
-
@frame_handler(FrameType.RESPONSE_SCHEDULES
|
|
126
|
+
@frame_handler(FrameType.RESPONSE_SCHEDULES)
|
|
127
|
+
@contains(SchedulesStructure)
|
|
125
128
|
class SchedulesResponse(Response):
|
|
126
129
|
"""Represents response to a device schedules request."""
|
|
127
130
|
|
|
@@ -172,9 +175,8 @@ class SetThermostatParameterResponse(Response):
|
|
|
172
175
|
__slots__ = ()
|
|
173
176
|
|
|
174
177
|
|
|
175
|
-
@frame_handler(
|
|
176
|
-
|
|
177
|
-
)
|
|
178
|
+
@frame_handler(FrameType.RESPONSE_THERMOSTAT_PARAMETERS)
|
|
179
|
+
@contains(ThermostatParametersStructure)
|
|
178
180
|
class ThermostatParametersResponse(Response):
|
|
179
181
|
"""Represents a thermostat parameters response.
|
|
180
182
|
|
|
@@ -184,7 +186,8 @@ class ThermostatParametersResponse(Response):
|
|
|
184
186
|
__slots__ = ()
|
|
185
187
|
|
|
186
188
|
|
|
187
|
-
@frame_handler(FrameType.RESPONSE_UID
|
|
189
|
+
@frame_handler(FrameType.RESPONSE_UID)
|
|
190
|
+
@contains(ProductInfoStructure)
|
|
188
191
|
class UIDResponse(Response):
|
|
189
192
|
"""Represents an UID response.
|
|
190
193
|
|
|
@@ -42,7 +42,7 @@ def unpack_parameter(
|
|
|
42
42
|
|
|
43
43
|
def is_valid_parameter(data: bytes) -> bool:
|
|
44
44
|
"""Check if parameter contains any bytes besides 0xFF."""
|
|
45
|
-
return any(x for x in data
|
|
45
|
+
return any(x != BYTE_UNDEFINED for x in data)
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
@dataclass(slots=True, frozen=True)
|
|
@@ -230,7 +230,14 @@ class FrameReader:
|
|
|
230
230
|
econet_version=econet_version,
|
|
231
231
|
message=payload_bytes[FRAME_TYPE_SIZE:],
|
|
232
232
|
)
|
|
233
|
-
|
|
233
|
+
# Log raw bytes only. Formatting the frame itself would decode
|
|
234
|
+
# it before it's assigned to the device and hide the bytes of
|
|
235
|
+
# frames that fail to decode.
|
|
236
|
+
_LOGGER.debug(
|
|
237
|
+
"Received frame: %s, bytes: %s",
|
|
238
|
+
frame.__class__.__name__,
|
|
239
|
+
frame_bytes.hex(),
|
|
240
|
+
)
|
|
234
241
|
|
|
235
242
|
return frame
|
|
236
243
|
|
|
@@ -5,8 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from collections.abc import Generator
|
|
6
6
|
from typing import Any, Final
|
|
7
7
|
|
|
8
|
-
from pyplumio.
|
|
9
|
-
from pyplumio.parameters import ParameterValues
|
|
8
|
+
from pyplumio.parameters import ParameterValues, unpack_parameter
|
|
10
9
|
from pyplumio.structures import StructureDecoder
|
|
11
10
|
from pyplumio.structures.ecomax_parameters import ECOMAX_PARAMETER_SIZE
|
|
12
11
|
|
|
@@ -14,14 +13,7 @@ ATTR_ECOMAX_EXTENDED_PARAMETERS: Final = "ecomax_extended_parameters"
|
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
class EcomaxExtendedParametersStructure(StructureDecoder):
|
|
17
|
-
"""Represents an ecoMAX extended parameters structure.
|
|
18
|
-
|
|
19
|
-
Starts with number of parameters and index of the first parameter,
|
|
20
|
-
followed by value, minimum value and maximum value of each
|
|
21
|
-
parameter, one byte each. Unlike the regular parameter table, zero
|
|
22
|
-
bytes are valid here, so a parameter is skipped only if all of its
|
|
23
|
-
bytes are 0xFF.
|
|
24
|
-
"""
|
|
16
|
+
"""Represents an ecoMAX extended parameters structure."""
|
|
25
17
|
|
|
26
18
|
__slots__ = ()
|
|
27
19
|
|
|
@@ -30,9 +22,8 @@ class EcomaxExtendedParametersStructure(StructureDecoder):
|
|
|
30
22
|
) -> Generator[tuple[int, ParameterValues]]:
|
|
31
23
|
"""Unpack an ecoMAX extended parameter."""
|
|
32
24
|
for index in range(start, start + count):
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
yield (index, ParameterValues(*values))
|
|
25
|
+
if parameter := unpack_parameter(message, self._offset):
|
|
26
|
+
yield (index, parameter)
|
|
36
27
|
|
|
37
28
|
self._offset += ECOMAX_PARAMETER_SIZE
|
|
38
29
|
|
|
@@ -132,9 +132,13 @@ async def test_ecomax_handle_frame(
|
|
|
132
132
|
)
|
|
133
133
|
@patch("asyncio.Queue.put_nowait")
|
|
134
134
|
@class_from_json(SensorDataMessage, "messages/sensor_data.json", arguments=("message",))
|
|
135
|
+
@class_from_json(
|
|
136
|
+
RegulatorDataMessage, "messages/regulator_data.json", arguments=("message",)
|
|
137
|
+
)
|
|
135
138
|
async def test_frame_versions_tracker(
|
|
136
139
|
mock_put_nowait,
|
|
137
140
|
ecomax: EcoMAX,
|
|
141
|
+
regulator_data: RegulatorDataMessage,
|
|
138
142
|
sensor_data: SensorDataMessage,
|
|
139
143
|
frame_type: FrameType,
|
|
140
144
|
frame_request: Request,
|
|
@@ -160,6 +164,23 @@ async def test_frame_versions_tracker(
|
|
|
160
164
|
|
|
161
165
|
mock_put_nowait.assert_called_once_with(frame_request)
|
|
162
166
|
|
|
167
|
+
# Test with multiple source frames (sensors from before + regdata).
|
|
168
|
+
frame_versions_1 = ecomax.get_nowait(ATTR_FRAME_VERSIONS)
|
|
169
|
+
assert frame_versions_1 == {frame_type: 2}
|
|
170
|
+
ecomax.handle_frame(regulator_data)
|
|
171
|
+
await ecomax.wait_until_done()
|
|
172
|
+
frame_versions_2 = ecomax.get_nowait(ATTR_FRAME_VERSIONS)
|
|
173
|
+
assert frame_versions_2 == {
|
|
174
|
+
frame_type: 2,
|
|
175
|
+
FrameType.REQUEST_REGULATOR_DATA_SCHEMA: 0,
|
|
176
|
+
84: 0,
|
|
177
|
+
FrameType.REQUEST_ECOMAX_EXTENDED_PARAMETERS: 359,
|
|
178
|
+
FrameType.REQUEST_ALERTS: 53918,
|
|
179
|
+
FrameType.REQUEST_SCHEDULES: 1,
|
|
180
|
+
100: 1,
|
|
181
|
+
FrameType.REQUEST_PROGRAM_VERSION: 0,
|
|
182
|
+
}
|
|
183
|
+
|
|
163
184
|
|
|
164
185
|
@patch("asyncio.Queue.put_nowait")
|
|
165
186
|
async def test_frame_versions_tracker_extended_parameters(
|
|
@@ -10,9 +10,10 @@ import pytest
|
|
|
10
10
|
|
|
11
11
|
from pyplumio.const import ATTR_FRAME_ERRORS, DeviceType, FrameType
|
|
12
12
|
from pyplumio.devices import Device, PhysicalDevice, device_handler, get_device_handler
|
|
13
|
-
from pyplumio.exceptions import RequestError, UnknownDeviceError
|
|
13
|
+
from pyplumio.exceptions import FrameDataError, RequestError, UnknownDeviceError
|
|
14
14
|
from pyplumio.filters import on_change
|
|
15
15
|
from pyplumio.frames import Response
|
|
16
|
+
from pyplumio.frames.messages import SensorDataMessage
|
|
16
17
|
from pyplumio.parameters import Parameter
|
|
17
18
|
from pyplumio.structures.frame_versions import ATTR_FRAME_VERSIONS
|
|
18
19
|
from pyplumio.structures.network_info import NetworkInfo
|
|
@@ -124,7 +125,8 @@ class TestPhysicalDevice:
|
|
|
124
125
|
) -> None:
|
|
125
126
|
"""Test event listener for frame versions."""
|
|
126
127
|
assert physical_device.has_frame_version(frame_type, 1) is False
|
|
127
|
-
await physical_device.on_event_frame_versions({frame_type: 1})
|
|
128
|
+
frame_versions = await physical_device.on_event_frame_versions({frame_type: 1})
|
|
129
|
+
assert frame_versions == {frame_type: 1}
|
|
128
130
|
mock_request_create.assert_awaited_once_with(
|
|
129
131
|
requested_frame_type, recipient=DummyPhysicalDevice.address
|
|
130
132
|
)
|
|
@@ -157,6 +159,18 @@ class TestPhysicalDevice:
|
|
|
157
159
|
mock_assign_to.assert_called_once_with(physical_device)
|
|
158
160
|
mock_dispatch_nowait.assert_called_once_with("test", True)
|
|
159
161
|
|
|
162
|
+
@patch("pyplumio.devices.PhysicalDevice.dispatch_nowait")
|
|
163
|
+
async def test_handle_frame_with_decode_error(
|
|
164
|
+
self, mock_dispatch_nowait, physical_device: PhysicalDevice
|
|
165
|
+
) -> None:
|
|
166
|
+
"""Test that frame data error propagates and nothing is dispatched."""
|
|
167
|
+
frame = SensorDataMessage(message=b"")
|
|
168
|
+
with pytest.raises(FrameDataError, match="SensorDataMessage"):
|
|
169
|
+
physical_device.handle_frame(frame)
|
|
170
|
+
|
|
171
|
+
assert frame.handler is physical_device
|
|
172
|
+
mock_dispatch_nowait.assert_not_called()
|
|
173
|
+
|
|
160
174
|
@patch("pyplumio.devices.PhysicalDevice.get")
|
|
161
175
|
@patch("pyplumio.frames.Request.create", autospec=True)
|
|
162
176
|
@patch("asyncio.Queue.put_nowait")
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import struct
|
|
6
|
+
|
|
5
7
|
import pytest
|
|
6
8
|
from tests.conftest import RAISES
|
|
7
9
|
|
|
8
10
|
from pyplumio.const import DeviceType, FrameType
|
|
9
|
-
from pyplumio.exceptions import UnknownFrameError
|
|
11
|
+
from pyplumio.exceptions import FrameDataError, UnknownFrameError
|
|
10
12
|
from pyplumio.frames import (
|
|
11
13
|
ECONET_TYPE,
|
|
12
14
|
ECONET_VERSION,
|
|
@@ -17,7 +19,8 @@ from pyplumio.frames import (
|
|
|
17
19
|
get_frame_handler,
|
|
18
20
|
struct_header,
|
|
19
21
|
)
|
|
20
|
-
from pyplumio.frames.
|
|
22
|
+
from pyplumio.frames.messages import SensorDataMessage
|
|
23
|
+
from pyplumio.frames.responses import PasswordResponse, ProgramVersionResponse
|
|
21
24
|
from pyplumio.structures.network_info import NetworkInfoStructure
|
|
22
25
|
from pyplumio.structures.program_version import ATTR_VERSION, VersionInfo
|
|
23
26
|
|
|
@@ -162,6 +165,27 @@ def test_message_setter():
|
|
|
162
165
|
assert frame.data[ATTR_VERSION].struct_version == 6
|
|
163
166
|
|
|
164
167
|
|
|
168
|
+
@pytest.mark.parametrize(
|
|
169
|
+
("frame", "message"),
|
|
170
|
+
[
|
|
171
|
+
(SensorDataMessage(), "0010000000"),
|
|
172
|
+
(SensorDataMessage(), ""),
|
|
173
|
+
(PasswordResponse(), "00ff"),
|
|
174
|
+
],
|
|
175
|
+
ids=["struct_error", "index_error", "unicode_decode_error"],
|
|
176
|
+
)
|
|
177
|
+
def test_data_decode_error(frame: Response, message: str) -> None:
|
|
178
|
+
"""Test that decoding errors are raised as frame data errors."""
|
|
179
|
+
frame.message = bytes.fromhex(message)
|
|
180
|
+
with pytest.raises(FrameDataError, match=f"Message: {message}$") as exc_info:
|
|
181
|
+
_ = frame.data
|
|
182
|
+
|
|
183
|
+
assert frame.__class__.__name__ in str(exc_info.value)
|
|
184
|
+
assert isinstance(
|
|
185
|
+
exc_info.value.__cause__, (struct.error, IndexError, UnicodeDecodeError)
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
165
189
|
def test_request_repr(request_frame: Request) -> None:
|
|
166
190
|
"""Test a request class serialiazible representation."""
|
|
167
191
|
assert repr(request_frame) == (
|
|
@@ -190,16 +214,17 @@ def test_response_repr(response_frame: Response) -> None:
|
|
|
190
214
|
|
|
191
215
|
def test_frame_handler() -> None:
|
|
192
216
|
"""Test frame type decorator."""
|
|
193
|
-
wrapper = frame_handler(
|
|
194
|
-
FrameType.RESPONSE_DEVICE_AVAILABLE, contains=NetworkInfoStructure
|
|
195
|
-
)
|
|
217
|
+
wrapper = frame_handler(FrameType.RESPONSE_DEVICE_AVAILABLE)
|
|
196
218
|
response = wrapper(ResponseFrame)()
|
|
197
219
|
assert response.frame_type == FrameType.RESPONSE_DEVICE_AVAILABLE
|
|
198
|
-
assert NetworkInfoStructure in response.structures
|
|
199
220
|
|
|
200
221
|
|
|
201
222
|
def test_contains() -> None:
|
|
202
223
|
"""Test contains decorator."""
|
|
224
|
+
wrapper = contains(NetworkInfoStructure)
|
|
225
|
+
frame = wrapper(ResponseFrame)()
|
|
226
|
+
assert NetworkInfoStructure in frame.structures
|
|
227
|
+
|
|
203
228
|
wrapper = contains(NetworkInfoStructure, container="wrap")
|
|
204
229
|
frame = wrapper(ResponseFrame)()
|
|
205
230
|
assert NetworkInfoStructure in frame.structures
|
|
@@ -59,6 +59,7 @@ def fixture_switch(ecomax: EcoMAX) -> Switch:
|
|
|
59
59
|
[
|
|
60
60
|
(bytes([BYTE_UNDEFINED, 0xFE, BYTE_UNDEFINED, BYTE_UNDEFINED]), True),
|
|
61
61
|
(bytes([BYTE_UNDEFINED] * 4), False),
|
|
62
|
+
(b"\0" * 4, True),
|
|
62
63
|
],
|
|
63
64
|
)
|
|
64
65
|
def test_is_valid_parameter(data: bytes, expected_result: bool) -> None:
|
|
@@ -358,6 +358,34 @@ class TestFrameReader:
|
|
|
358
358
|
assert mock_readexactly.call_count == 2
|
|
359
359
|
mock_readexactly.assert_has_calls([call(6), call(5)])
|
|
360
360
|
|
|
361
|
+
@patch("pyplumio.frames.Request.decode_message")
|
|
362
|
+
@patch("asyncio.StreamReader.read", return_value=(b"\x00\x68"))
|
|
363
|
+
@patch(
|
|
364
|
+
"asyncio.StreamReader.readexactly",
|
|
365
|
+
side_effect=(b"\x0c\x00\x00\x56\x30\x05", b"\x31\xff\x00\xc9\x16"),
|
|
366
|
+
)
|
|
367
|
+
async def test_read_does_not_decode(
|
|
368
|
+
self,
|
|
369
|
+
mock_readexactly,
|
|
370
|
+
mock_read,
|
|
371
|
+
mock_decode_message,
|
|
372
|
+
frame_reader: FrameReader,
|
|
373
|
+
caplog,
|
|
374
|
+
) -> None:
|
|
375
|
+
"""Test that reading a frame with debug logging doesn't decode it.
|
|
376
|
+
|
|
377
|
+
Frame must only be decoded after it's assigned to the device.
|
|
378
|
+
"""
|
|
379
|
+
with caplog.at_level(logging.DEBUG):
|
|
380
|
+
frame = await frame_reader.read()
|
|
381
|
+
|
|
382
|
+
assert isinstance(frame, EcomaxParametersRequest)
|
|
383
|
+
mock_decode_message.assert_not_called()
|
|
384
|
+
assert (
|
|
385
|
+
"Received frame: EcomaxParametersRequest, bytes: 680c0000563005"
|
|
386
|
+
"31ff00c916" in caplog.text
|
|
387
|
+
)
|
|
388
|
+
|
|
361
389
|
@patch("asyncio.StreamReader.read", return_value=False)
|
|
362
390
|
async def test_broken_connection(
|
|
363
391
|
self, mock_read, frame_reader: FrameReader
|
|
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
|
|
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
|
|
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
|
|
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
|
{pyplumio-0.7.1 → pyplumio-0.7.2}/tests/testdata/requests/set_ecomax_extended_parameter.json
RENAMED
|
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
|