PyPlumIO 0.7.9__tar.gz → 0.7.10__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.
Files changed (157) hide show
  1. {pyplumio-0.7.9 → pyplumio-0.7.10}/PKG-INFO +2 -1
  2. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/devices/ecomax.py +46 -12
  3. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/helpers/event_manager.py +28 -6
  4. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/protocol.py +3 -0
  5. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyproject.toml +2 -1
  6. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/test_ecomax.py +255 -11
  7. pyplumio-0.7.10/tests/helpers/test_event_manager.py +483 -0
  8. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_protocol.py +28 -1
  9. pyplumio-0.7.9/tests/helpers/test_event_manager.py +0 -237
  10. {pyplumio-0.7.9 → pyplumio-0.7.10}/.gitignore +0 -0
  11. {pyplumio-0.7.9 → pyplumio-0.7.10}/LICENSE +0 -0
  12. {pyplumio-0.7.9 → pyplumio-0.7.10}/README.md +0 -0
  13. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/Makefile +0 -0
  14. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/make.bat +0 -0
  15. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/callbacks.rst +0 -0
  16. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/cli.rst +0 -0
  17. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/conf.py +0 -0
  18. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/connecting.rst +0 -0
  19. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/custom_parameters.rst +0 -0
  20. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/frames.rst +0 -0
  21. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/index.rst +0 -0
  22. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/mixers_thermostats.rst +0 -0
  23. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/protocol.rst +0 -0
  24. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/reading.rst +0 -0
  25. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/schedules.rst +0 -0
  26. {pyplumio-0.7.9 → pyplumio-0.7.10}/docs/source/writing.rst +0 -0
  27. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/__init__.py +0 -0
  28. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/__main__.py +0 -0
  29. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/__init__.py +0 -0
  30. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/app.py +0 -0
  31. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/codegen.py +0 -0
  32. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/model.py +0 -0
  33. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/session.py +0 -0
  34. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/state.py +0 -0
  35. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/cli/ui.py +0 -0
  36. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/connection.py +0 -0
  37. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/const.py +0 -0
  38. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/data_types.py +0 -0
  39. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/devices/__init__.py +0 -0
  40. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/devices/ecoster.py +0 -0
  41. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/devices/mixer.py +0 -0
  42. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/devices/thermostat.py +0 -0
  43. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/exceptions.py +0 -0
  44. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/filters.py +0 -0
  45. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/frames/__init__.py +0 -0
  46. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/frames/messages.py +0 -0
  47. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/frames/requests.py +0 -0
  48. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/frames/responses.py +0 -0
  49. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/helpers/__init__.py +0 -0
  50. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/helpers/async_cache.py +0 -0
  51. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/helpers/task_manager.py +0 -0
  52. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/__init__.py +0 -0
  53. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/custom/__init__.py +0 -0
  54. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/custom/ecomax_350p2_zf.py +0 -0
  55. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/custom/ecomax_860d3_hb.py +0 -0
  56. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/custom/ecomax_860p4_nm_touch.py +0 -0
  57. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/ecomax.py +0 -0
  58. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/mixer.py +0 -0
  59. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/parameters/thermostat.py +0 -0
  60. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/py.typed +0 -0
  61. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/stream.py +0 -0
  62. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/__init__.py +0 -0
  63. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/alerts.py +0 -0
  64. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/ecomax_parameters.py +0 -0
  65. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/ecomax_service_parameters.py +0 -0
  66. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/frame_versions.py +0 -0
  67. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/mixer_parameters.py +0 -0
  68. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/network_info.py +0 -0
  69. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/product_info.py +0 -0
  70. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/program_version.py +0 -0
  71. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/regulator_data.py +0 -0
  72. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/regulator_data_schema.py +0 -0
  73. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/schedules.py +0 -0
  74. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/sensor_data.py +0 -0
  75. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/structures/thermostat_parameters.py +0 -0
  76. {pyplumio-0.7.9 → pyplumio-0.7.10}/pyplumio/utils.py +0 -0
  77. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/__init__.py +0 -0
  78. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/__init__.py +0 -0
  79. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/conftest.py +0 -0
  80. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_app.py +0 -0
  81. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_codegen.py +0 -0
  82. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_init.py +0 -0
  83. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_model.py +0 -0
  84. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_session.py +0 -0
  85. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_state.py +0 -0
  86. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/cli/test_ui.py +0 -0
  87. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/conftest.py +0 -0
  88. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/__init__.py +0 -0
  89. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/test_ecoster.py +0 -0
  90. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/test_init.py +0 -0
  91. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/test_mixer.py +0 -0
  92. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/devices/test_thermostat.py +0 -0
  93. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/frames/test_init.py +0 -0
  94. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/frames/test_messages.py +0 -0
  95. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/frames/test_requests.py +0 -0
  96. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/frames/test_responses.py +0 -0
  97. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/helpers/__init__.py +0 -0
  98. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/helpers/test_async_cache.py +0 -0
  99. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/helpers/test_task_manager.py +0 -0
  100. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/helpers/test_uid.py +0 -0
  101. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/__init__.py +0 -0
  102. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/custom/__init__.py +0 -0
  103. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/custom/test_ecomax_350p2_zf.py +0 -0
  104. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/custom/test_ecomax_860d3_hb.py +0 -0
  105. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/custom/test_ecomax_860p4_nm_touch.py +0 -0
  106. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/custom/test_init.py +0 -0
  107. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/test_ecomax.py +0 -0
  108. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/test_init.py +0 -0
  109. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/test_mixers.py +0 -0
  110. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/parameters/test_thermostats.py +0 -0
  111. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/ruff.toml +0 -0
  112. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/__init__.py +0 -0
  113. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_alerts.py +0 -0
  114. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_ecomax_parameters.py +0 -0
  115. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_ecomax_service_parameters.py +0 -0
  116. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_frame_versions.py +0 -0
  117. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_mixer_parameters.py +0 -0
  118. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_product_info.py +0 -0
  119. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_program_version.py +0 -0
  120. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/structures/test_schedules.py +0 -0
  121. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_connection.py +0 -0
  122. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_const.py +0 -0
  123. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_data_types.py +0 -0
  124. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_filters.py +0 -0
  125. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_init.py +0 -0
  126. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_main.py +0 -0
  127. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_stream.py +0 -0
  128. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/test_utils.py +0 -0
  129. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/messages/regulator_data.json +0 -0
  130. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/messages/sensor_data.json +0 -0
  131. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/parameters/ecomax_350p2_zf.json +0 -0
  132. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/parameters/ecomax_860d3_hb.json +0 -0
  133. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/parameters/ecomax_860p4_nm_touch.json +0 -0
  134. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/alerts.json +0 -0
  135. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/ecomax_control.json +0 -0
  136. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/ecomax_parameters.json +0 -0
  137. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/ecomax_service_parameters.json +0 -0
  138. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/mixer_parameters.json +0 -0
  139. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/set_ecomax_parameter.json +0 -0
  140. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/set_ecomax_service_parameter.json +0 -0
  141. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/set_mixer_parameter.json +0 -0
  142. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/set_schedule.json +0 -0
  143. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/set_thermostat_parameter.json +0 -0
  144. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/requests/thermostat_parameters.json +0 -0
  145. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/alerts.json +0 -0
  146. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/device_available.json +0 -0
  147. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/ecomax_parameters.json +0 -0
  148. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/ecomax_service_parameters.json +0 -0
  149. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/mixer_parameters.json +0 -0
  150. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/password.json +0 -0
  151. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/program_version.json +0 -0
  152. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/regulator_data_schema.json +0 -0
  153. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/schedules.json +0 -0
  154. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/thermostat_parameters.json +0 -0
  155. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/responses/uid.json +0 -0
  156. {pyplumio-0.7.9 → pyplumio-0.7.10}/tests/testdata/unknown/unknown_ecomax_parameter.json +0 -0
  157. {pyplumio-0.7.9 → pyplumio-0.7.10}/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.9
3
+ Version: 0.7.10
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
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: 3.15
19
20
  Classifier: Topic :: Home Automation
20
21
  Classifier: Topic :: Software Development :: Libraries
21
22
  Classifier: Typing :: Typed
@@ -9,6 +9,7 @@ import time
9
9
  from typing import Any, Final, NamedTuple
10
10
 
11
11
  from pyplumio.const import (
12
+ ATTR_CONNECTED,
12
13
  ATTR_FRAME_ERRORS,
13
14
  ATTR_PASSWORD,
14
15
  ATTR_SENSORS,
@@ -60,7 +61,12 @@ from pyplumio.structures.schedules import (
60
61
  ScheduleSwitch,
61
62
  ScheduleSwitchDescription,
62
63
  )
63
- from pyplumio.structures.sensor_data import ATTR_MIXER_SENSORS, ATTR_THERMOSTAT_SENSORS
64
+ from pyplumio.structures.sensor_data import (
65
+ ATTR_MIXER_SENSORS,
66
+ ATTR_MIXERS_CONNECTED,
67
+ ATTR_THERMOSTAT_SENSORS,
68
+ ATTR_THERMOSTATS_CONNECTED,
69
+ )
64
70
  from pyplumio.structures.thermostat_parameters import ATTR_THERMOSTAT_PARAMETERS
65
71
 
66
72
  _LOGGER = logging.getLogger(__name__)
@@ -123,10 +129,11 @@ class _FuelMeter:
123
129
 
124
130
 
125
131
  class DataKey(NamedTuple):
126
- """Map a data key to frame type."""
132
+ """Map a data key to frame type and optional prerequisite sensor key."""
127
133
 
128
134
  key: str
129
135
  provided_by: FrameType
136
+ prerequisite: str | None = None
130
137
 
131
138
 
132
139
  REQUIRED_KEYS: tuple[DataKey, ...] = (
@@ -138,12 +145,20 @@ REQUIRED_KEYS: tuple[DataKey, ...] = (
138
145
  ),
139
146
  DataKey(ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS),
140
147
  DataKey(ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
141
- DataKey(ATTR_MIXER_PARAMETERS, FrameType.REQUEST_MIXER_PARAMETERS),
142
- DataKey(ATTR_THERMOSTAT_PARAMETERS, FrameType.REQUEST_THERMOSTAT_PARAMETERS),
148
+ DataKey(
149
+ ATTR_MIXER_PARAMETERS,
150
+ FrameType.REQUEST_MIXER_PARAMETERS,
151
+ ATTR_MIXERS_CONNECTED,
152
+ ),
153
+ DataKey(
154
+ ATTR_THERMOSTAT_PARAMETERS,
155
+ FrameType.REQUEST_THERMOSTAT_PARAMETERS,
156
+ ATTR_THERMOSTATS_CONNECTED,
157
+ ),
143
158
  DataKey(ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
144
159
  )
145
160
 
146
- REQUIRED_TYPES = [frame_type for _, frame_type in REQUIRED_KEYS]
161
+ REQUIRED_TYPES = [data_key.provided_by for data_key in REQUIRED_KEYS]
147
162
 
148
163
  WAIT_FOR_SETUP_SECONDS: Final = 60.0
149
164
 
@@ -250,6 +265,18 @@ class EcoMAX(PhysicalDevice):
250
265
  await asyncio.gather(*(device.shutdown() for device in devices))
251
266
  await super().shutdown()
252
267
 
268
+ def _should_request_setup_key(self, data_key: DataKey) -> bool:
269
+ """Return True if the setup data key needs to be requested."""
270
+ if data_key.key in self.data or not self.supports_frame_type(
271
+ data_key.provided_by
272
+ ):
273
+ return False
274
+
275
+ if data_key.prerequisite is not None:
276
+ return bool(self.get_nowait(data_key.prerequisite, 0))
277
+
278
+ return True
279
+
253
280
  @event_listener
254
281
  async def on_event_setup(self, setup: bool) -> bool:
255
282
  """Request frames required to set up an ecoMAX entry."""
@@ -264,14 +291,21 @@ class EcoMAX(PhysicalDevice):
264
291
  )
265
292
  return False
266
293
 
267
- results = await asyncio.gather(
268
- *(self.request(key, frame_type) for key, frame_type in REQUIRED_KEYS),
269
- return_exceptions=True,
270
- )
294
+ errors: list[FrameType] = []
295
+ for data_key in REQUIRED_KEYS:
296
+ if not self.get_nowait(ATTR_CONNECTED, True):
297
+ return False
298
+
299
+ if not self._should_request_setup_key(data_key):
300
+ continue
301
+
302
+ try:
303
+ await self.request(data_key.key, data_key.provided_by)
304
+ except RequestError as request_error:
305
+ if not self.get_nowait(ATTR_CONNECTED, True):
306
+ return False
271
307
 
272
- errors = [
273
- result.frame_type for result in results if isinstance(result, RequestError)
274
- ]
308
+ errors.append(request_error.frame_type)
275
309
 
276
310
  if errors:
277
311
  self.dispatch_nowait(ATTR_FRAME_ERRORS, errors)
@@ -65,11 +65,12 @@ StopPropagation = StopPropagationType(object())
65
65
  class EventManager(TaskManager, Generic[_EventDataT]):
66
66
  """Represents an event manager."""
67
67
 
68
- __slots__ = ("_data", "_events", "_callbacks")
68
+ __slots__ = ("_data", "_events", "_callbacks", "_listeners")
69
69
 
70
70
  _data: dict[str, _EventDataT]
71
71
  _events: dict[str, asyncio.Event]
72
72
  _callbacks: dict[str, list[EventCallback]]
73
+ _listeners: dict[str, list[EventCallback]]
73
74
 
74
75
  def __init__(self) -> None:
75
76
  """Initialize a new event manager."""
@@ -77,6 +78,7 @@ class EventManager(TaskManager, Generic[_EventDataT]):
77
78
  self._data = {}
78
79
  self._events = {}
79
80
  self._callbacks = {}
81
+ self._listeners = {}
80
82
  self._register_event_listeners()
81
83
 
82
84
  def __getattr__(self, name: str) -> _EventDataT:
@@ -90,7 +92,8 @@ class EventManager(TaskManager, Generic[_EventDataT]):
90
92
  """Register the event listeners."""
91
93
  for event, callback in self.event_listeners():
92
94
  filter_func = getattr(callback, "_on_event_filter", None)
93
- self.subscribe(event, filter_func(callback) if filter_func else callback)
95
+ listeners = self._listeners.setdefault(event, [])
96
+ listeners.append(filter_func(callback) if filter_func else callback)
94
97
 
95
98
  def event_listeners(self) -> Generator[tuple[str, EventCallback]]:
96
99
  """Get the event listeners."""
@@ -210,9 +213,14 @@ class EventManager(TaskManager, Generic[_EventDataT]):
210
213
 
211
214
  return False
212
215
 
213
- async def dispatch(self, name: str, value: _EventDataT) -> None:
214
- """Call registered callbacks and dispatch the event."""
215
- callbacks = self._callbacks.get(name, [])
216
+ async def _run_callbacks(
217
+ self,
218
+ callbacks: list[EventCallback],
219
+ value: _EventDataT,
220
+ *,
221
+ update_data_key: str | None = None,
222
+ ) -> tuple[_EventDataT, bool]:
223
+ """Run callbacks sequentially, returning the updated value and stop flag."""
216
224
  for callback in list(callbacks):
217
225
  try:
218
226
  result = await callback(value)
@@ -225,13 +233,27 @@ class EventManager(TaskManager, Generic[_EventDataT]):
225
233
  if result is None:
226
234
  continue
227
235
  elif result is StopPropagation:
228
- break
236
+ return (value, True)
229
237
  else:
230
238
  value = result
239
+ if update_data_key is not None:
240
+ self._data[update_data_key] = value
241
+
242
+ return (value, False)
243
+
244
+ async def dispatch(self, name: str, value: _EventDataT) -> None:
245
+ """Call registered callbacks and dispatch the event."""
246
+ if listeners := self._listeners.get(name):
247
+ value, stopped = await self._run_callbacks(listeners, value)
248
+ else:
249
+ stopped = False
231
250
 
232
251
  self._data[name] = value
233
252
  self.set_event(name)
234
253
 
254
+ if not stopped and (callbacks := self._callbacks.get(name)):
255
+ await self._run_callbacks(callbacks, value, update_data_key=name)
256
+
235
257
  def dispatch_nowait(self, name: str, value: _EventDataT) -> None:
236
258
  """Call a registered callbacks and dispatch the event without waiting."""
237
259
  self.create_task(self.dispatch(name, value))
@@ -241,6 +241,8 @@ class AsyncProtocol(Protocol, EventManager[PhysicalDevice]):
241
241
  self.statistics.connected_since = datetime.now()
242
242
  for device in self.data.values():
243
243
  device.dispatch_nowait(ATTR_CONNECTED, True)
244
+ if device.get_nowait(ATTR_SETUP) is False:
245
+ device.dispatch_nowait(ATTR_SETUP, True)
244
246
 
245
247
  def _mark_disconnected(self) -> None:
246
248
  """Mark connection as disconnected."""
@@ -259,6 +261,7 @@ class AsyncProtocol(Protocol, EventManager[PhysicalDevice]):
259
261
  async def connection_lost(self) -> None:
260
262
  """Close the connection and call connection lost callbacks."""
261
263
  if self.connected.is_set():
264
+ self._clear_write_queue()
262
265
  self._mark_disconnected()
263
266
  await self._close_writer()
264
267
  await asyncio.gather(*(callback() for callback in self.on_connection_lost))
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyPlumIO"
3
- version = "0.7.9"
3
+ version = "0.7.10"
4
4
  authors = [
5
5
  {name = "Denis Paavilainen", email = "denpa@denpa.pro"}
6
6
  ]
@@ -17,6 +17,7 @@ classifiers = [
17
17
  "Programming Language :: Python :: 3.12",
18
18
  "Programming Language :: Python :: 3.13",
19
19
  "Programming Language :: Python :: 3.14",
20
+ "Programming Language :: Python :: 3.15",
20
21
  "Topic :: Software Development :: Libraries",
21
22
  "Topic :: Home Automation",
22
23
  "Typing :: Typed",
@@ -4,15 +4,17 @@ import asyncio
4
4
  from datetime import timedelta
5
5
  import logging
6
6
  from typing import Any, Final, cast
7
- from unittest.mock import AsyncMock, Mock, patch
7
+ from unittest.mock import AsyncMock, Mock, call, patch
8
8
 
9
9
  import pytest
10
10
 
11
11
  from pyplumio.const import (
12
+ ATTR_CONNECTED,
12
13
  ATTR_FRAME_ERRORS,
13
14
  ATTR_INDEX,
14
15
  ATTR_OFFSET,
15
16
  ATTR_PARAMETER,
17
+ ATTR_PASSWORD,
16
18
  ATTR_SCHEDULE,
17
19
  ATTR_SENSORS,
18
20
  ATTR_SETUP,
@@ -33,7 +35,7 @@ from pyplumio.devices.ecomax import (
33
35
  ATTR_FUEL_BURNED,
34
36
  ATTR_MIXERS,
35
37
  ATTR_THERMOSTATS,
36
- REQUIRED_KEYS,
38
+ DataKey,
37
39
  EcoMAX,
38
40
  )
39
41
  from pyplumio.devices.mixer import Mixer
@@ -50,6 +52,7 @@ from pyplumio.frames.requests import (
50
52
  SetEcomaxServiceParameterRequest,
51
53
  SetScheduleRequest,
52
54
  SetThermostatParameterRequest,
55
+ StartMasterRequest,
53
56
  )
54
57
  from pyplumio.frames.responses import (
55
58
  EcomaxParametersResponse,
@@ -70,12 +73,18 @@ from pyplumio.parameters.ecomax import (
70
73
  EcomaxSwitchDescription,
71
74
  get_service_parameter_types,
72
75
  )
73
- from pyplumio.structures.ecomax_parameters import ATTR_ECOMAX_CONTROL
76
+ from pyplumio.protocol import AsyncProtocol
77
+ from pyplumio.structures.alerts import ATTR_TOTAL_ALERTS
78
+ from pyplumio.structures.ecomax_parameters import (
79
+ ATTR_ECOMAX_CONTROL,
80
+ ATTR_ECOMAX_PARAMETERS,
81
+ )
74
82
  from pyplumio.structures.ecomax_service_parameters import ATTR_ECOMAX_SERVICE_PARAMETERS
75
83
  from pyplumio.structures.frame_versions import ATTR_FRAME_VERSIONS
76
84
  from pyplumio.structures.mixer_parameters import ATTR_MIXER_PARAMETERS
77
85
  from pyplumio.structures.network_info import ATTR_NETWORK_INFO, NetworkInfo
78
86
  from pyplumio.structures.product_info import ATTR_PRODUCT, ProductInfo
87
+ from pyplumio.structures.regulator_data_schema import ATTR_REGDATA_SCHEMA
79
88
  from pyplumio.structures.schedules import (
80
89
  ATTR_SCHEDULE_PARAMETER,
81
90
  ATTR_SCHEDULE_SWITCH,
@@ -264,12 +273,85 @@ async def test_ecomax_shutdown(
264
273
  @patch("pyplumio.devices.ecomax.EcoMAX.wait_for")
265
274
  async def test_ecomax_setup(mock_wait_for, mock_request, ecomax: EcoMAX) -> None:
266
275
  """Test setting up an ecoMAX entry."""
276
+ in_flight = 0
277
+ max_in_flight = 0
278
+
279
+ async def _sequential_request(*args: Any, **kwargs: Any) -> None:
280
+ """Yield to the event loop and track concurrent in-flight requests."""
281
+ nonlocal in_flight, max_in_flight
282
+ in_flight += 1
283
+ max_in_flight = max(max_in_flight, in_flight)
284
+ loop = asyncio.get_running_loop()
285
+ future: asyncio.Future[None] = loop.create_future()
286
+ loop.call_soon(future.set_result, None)
287
+ await future
288
+ in_flight -= 1
289
+
290
+ mock_request.side_effect = _sequential_request
267
291
  ecomax.dispatch_nowait(ATTR_SETUP, True)
268
292
  await ecomax.wait_until_done()
293
+ assert ecomax.get_nowait(ATTR_SETUP) is True
269
294
  assert ATTR_FRAME_ERRORS not in ecomax.data
270
- assert mock_request.await_count == len(REQUIRED_KEYS)
295
+ assert max_in_flight == 1
296
+ assert mock_request.await_args_list == [
297
+ call(ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA),
298
+ call(ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
299
+ call(
300
+ ATTR_ECOMAX_SERVICE_PARAMETERS,
301
+ FrameType.REQUEST_ECOMAX_SERVICE_PARAMETERS,
302
+ ),
303
+ call(ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS),
304
+ call(ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
305
+ call(ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
306
+ ]
271
307
  mock_wait_for.assert_awaited_once_with(ATTR_SENSORS, timeout=60.0)
272
308
 
309
+ # Test with connected mixers and thermostats.
310
+ mock_request.reset_mock()
311
+ await ecomax.dispatch(ATTR_MIXERS_CONNECTED, 1)
312
+ await ecomax.dispatch(ATTR_THERMOSTATS_CONNECTED, 1)
313
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
314
+ await ecomax.wait_until_done()
315
+ assert ecomax.get_nowait(ATTR_SETUP) is True
316
+ assert max_in_flight == 1
317
+ assert mock_request.await_args_list == [
318
+ call(ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA),
319
+ call(ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
320
+ call(
321
+ ATTR_ECOMAX_SERVICE_PARAMETERS,
322
+ FrameType.REQUEST_ECOMAX_SERVICE_PARAMETERS,
323
+ ),
324
+ call(ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS),
325
+ call(ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
326
+ call(ATTR_MIXER_PARAMETERS, FrameType.REQUEST_MIXER_PARAMETERS),
327
+ call(ATTR_THERMOSTAT_PARAMETERS, FrameType.REQUEST_THERMOSTAT_PARAMETERS),
328
+ call(ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
329
+ ]
330
+
331
+ # Test skipping mixer/thermostat parameters when already in data.
332
+ await ecomax.dispatch(ATTR_MIXER_PARAMETERS, {0: {}})
333
+ await ecomax.dispatch(ATTR_THERMOSTAT_PARAMETERS, {0: {}})
334
+ assert (
335
+ ecomax._should_request_setup_key(
336
+ DataKey(
337
+ ATTR_MIXER_PARAMETERS,
338
+ FrameType.REQUEST_MIXER_PARAMETERS,
339
+ ATTR_MIXERS_CONNECTED,
340
+ )
341
+ )
342
+ is False
343
+ )
344
+ assert (
345
+ ecomax._should_request_setup_key(
346
+ DataKey(
347
+ ATTR_THERMOSTAT_PARAMETERS,
348
+ FrameType.REQUEST_THERMOSTAT_PARAMETERS,
349
+ ATTR_THERMOSTATS_CONNECTED,
350
+ )
351
+ )
352
+ is False
353
+ )
354
+
273
355
 
274
356
  @patch("pyplumio.devices.ecomax.EcoMAX.request")
275
357
  @patch("pyplumio.devices.ecomax.EcoMAX.wait_for", side_effect=(TimeoutError,))
@@ -284,18 +366,180 @@ async def test_ecomax_setup_failed(
284
366
  assert "no response from device for 60 seconds" in caplog.text
285
367
 
286
368
 
287
- @patch(
288
- "pyplumio.devices.ecomax.EcoMAX.request",
289
- side_effect=RequestError("test", FrameType.REQUEST_ALERTS),
290
- )
369
+ @patch("pyplumio.devices.ecomax.EcoMAX.request")
291
370
  @patch("pyplumio.devices.ecomax.EcoMAX.wait_for")
292
371
  async def test_ecomax_setup_errors(mock_wait_for, mock_request, ecomax: EcoMAX) -> None:
293
372
  """Test setting up an ecoMAX entry with frame errors."""
373
+
374
+ async def _request_with_error(key: str, frame_type: FrameType) -> None:
375
+ """Raise RequestError for alerts and succeed for other keys."""
376
+ if frame_type == FrameType.REQUEST_ALERTS:
377
+ raise RequestError("test", frame_type)
378
+
379
+ mock_request.side_effect = _request_with_error
294
380
  ecomax.dispatch_nowait(ATTR_SETUP, True)
295
381
  await ecomax.wait_until_done()
296
- assert FrameType.REQUEST_ALERTS in ecomax.get_nowait(ATTR_FRAME_ERRORS, [])
297
- assert mock_request.await_count == len(REQUIRED_KEYS)
298
- mock_wait_for.assert_awaited_once_with(ATTR_SENSORS, timeout=60.0)
382
+ assert ecomax.get_nowait(ATTR_FRAME_ERRORS, []) == [FrameType.REQUEST_ALERTS]
383
+ assert ecomax.get_nowait(ATTR_SETUP) is True
384
+ assert mock_request.await_args_list == [
385
+ call(ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA),
386
+ call(ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
387
+ call(
388
+ ATTR_ECOMAX_SERVICE_PARAMETERS,
389
+ FrameType.REQUEST_ECOMAX_SERVICE_PARAMETERS,
390
+ ),
391
+ call(ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS),
392
+ call(ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
393
+ call(ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
394
+ ]
395
+ assert (
396
+ ecomax._should_request_setup_key(
397
+ DataKey(ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS)
398
+ )
399
+ is False
400
+ )
401
+
402
+ # Re-running setup skips frame types already present in ATTR_FRAME_ERRORS.
403
+ mock_request.reset_mock()
404
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
405
+ await ecomax.wait_until_done()
406
+ assert mock_request.await_args_list == [
407
+ call(ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA),
408
+ call(ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
409
+ call(
410
+ ATTR_ECOMAX_SERVICE_PARAMETERS,
411
+ FrameType.REQUEST_ECOMAX_SERVICE_PARAMETERS,
412
+ ),
413
+ call(ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
414
+ call(ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
415
+ ]
416
+ mock_wait_for.assert_awaited_with(ATTR_SENSORS, timeout=60.0)
417
+
418
+
419
+ @patch("pyplumio.devices.ecomax.EcoMAX.request")
420
+ @patch("pyplumio.devices.ecomax.EcoMAX.wait_for")
421
+ async def test_ecomax_setup_disconnected(
422
+ mock_wait_for, mock_request, ecomax: EcoMAX
423
+ ) -> None:
424
+ """Test aborting ecoMAX setup when disconnected."""
425
+ # Disconnected before starting requests.
426
+ await ecomax.dispatch(ATTR_CONNECTED, False)
427
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
428
+ await ecomax.wait_until_done()
429
+ mock_request.assert_not_awaited()
430
+ assert ecomax.get_nowait(ATTR_SETUP) is False
431
+ assert ATTR_FRAME_ERRORS not in ecomax.data
432
+
433
+ # Disconnected mid-request when RequestError is raised.
434
+ async def _disconnect_and_fail(key: str, frame_type: FrameType) -> None:
435
+ """Mark device disconnected and raise RequestError."""
436
+ await ecomax.dispatch(ATTR_CONNECTED, False)
437
+ raise RequestError("test", frame_type)
438
+
439
+ await ecomax.dispatch(ATTR_CONNECTED, True)
440
+ mock_request.side_effect = _disconnect_and_fail
441
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
442
+ await ecomax.wait_until_done()
443
+ mock_request.assert_awaited_once_with(
444
+ ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA
445
+ )
446
+ assert ecomax.get_nowait(ATTR_SETUP) is False
447
+ assert ATTR_FRAME_ERRORS not in ecomax.data
448
+
449
+ # Disconnected between successful first request and second request.
450
+ async def _succeed_then_disconnect(key: str, frame_type: FrameType) -> None:
451
+ """Store first key and mark device disconnected before next iteration."""
452
+ await ecomax.dispatch(key, [])
453
+ await ecomax.dispatch(ATTR_CONNECTED, False)
454
+
455
+ mock_request.reset_mock()
456
+ await ecomax.dispatch(ATTR_CONNECTED, True)
457
+ mock_request.side_effect = _succeed_then_disconnect
458
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
459
+ await ecomax.wait_until_done()
460
+ mock_request.assert_awaited_once_with(
461
+ ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA
462
+ )
463
+ assert ATTR_REGDATA_SCHEMA in ecomax.data
464
+ assert ecomax.get_nowait(ATTR_SETUP) is False
465
+ assert ATTR_FRAME_ERRORS not in ecomax.data
466
+
467
+
468
+ async def test_ecomax_reconnect_resumes_setup() -> None:
469
+ """Test reconnecting after mid-setup disconnect resumes remaining keys."""
470
+ protocol = AsyncProtocol()
471
+ ecomax = EcoMAX(protocol._write_queue, NetworkInfo())
472
+ await ecomax.dispatch(ATTR_CONNECTED, True)
473
+ await ecomax.dispatch(ATTR_SENSORS, {ATTR_STATE: DeviceState.WORKING})
474
+ await ecomax.dispatch(
475
+ ATTR_PRODUCT,
476
+ ProductInfo(
477
+ type=ProductType.ECOMAX_P,
478
+ id=0,
479
+ uid="TEST",
480
+ logo=0,
481
+ image=0,
482
+ model=DUMMY_MODEL,
483
+ ),
484
+ )
485
+ await protocol.dispatch("ecomax", ecomax)
486
+
487
+ protocol.connected.set()
488
+ protocol.writer = AsyncMock()
489
+ protocol._write_queue.put_nowait(AlertsRequest(recipient=DeviceType.ECOMAX))
490
+
491
+ calls: list[tuple[str, FrameType]] = []
492
+
493
+ async def _request_with_disconnect(key: str, frame_type: FrameType) -> None:
494
+ """Simulate disconnect during second request and succeed on reconnect."""
495
+ calls.append((key, frame_type))
496
+ if len(calls) == 2 and ecomax.get_nowait(ATTR_SETUP) is None:
497
+ await protocol.connection_lost()
498
+ loop = asyncio.get_running_loop()
499
+ future: asyncio.Future[None] = loop.create_future()
500
+ loop.call_soon(future.set_result, None)
501
+ await future
502
+ raise RequestError("disconnected", frame_type)
503
+
504
+ await ecomax.dispatch(key, [])
505
+
506
+ with (
507
+ patch.object(EcoMAX, "request", side_effect=_request_with_disconnect),
508
+ patch.object(AsyncProtocol, "frame_handler", new_callable=AsyncMock),
509
+ ):
510
+ ecomax.dispatch_nowait(ATTR_SETUP, True)
511
+ await ecomax.wait_until_done()
512
+
513
+ assert ecomax.get_nowait(ATTR_SETUP) is False
514
+ assert ecomax.get_nowait(ATTR_CONNECTED) is False
515
+ assert ATTR_FRAME_ERRORS not in ecomax.data
516
+ assert protocol._write_queue.empty()
517
+ assert calls == [
518
+ (ATTR_REGDATA_SCHEMA, FrameType.REQUEST_REGULATOR_DATA_SCHEMA),
519
+ (ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
520
+ ]
521
+
522
+ calls.clear()
523
+ mock_reader = AsyncMock(spec=asyncio.StreamReader)
524
+ mock_writer = AsyncMock(spec=asyncio.StreamWriter)
525
+ protocol.connection_established(mock_reader, mock_writer)
526
+ await protocol.wait_until_done()
527
+ await ecomax.wait_until_done()
528
+
529
+ assert isinstance(protocol._write_queue.get_nowait(), StartMasterRequest)
530
+ assert ecomax.get_nowait(ATTR_CONNECTED) is True
531
+ assert ecomax.get_nowait(ATTR_SETUP) is True
532
+ assert ATTR_FRAME_ERRORS not in ecomax.data
533
+ assert calls == [
534
+ (ATTR_ECOMAX_PARAMETERS, FrameType.REQUEST_ECOMAX_PARAMETERS),
535
+ (
536
+ ATTR_ECOMAX_SERVICE_PARAMETERS,
537
+ FrameType.REQUEST_ECOMAX_SERVICE_PARAMETERS,
538
+ ),
539
+ (ATTR_TOTAL_ALERTS, FrameType.REQUEST_ALERTS),
540
+ (ATTR_SCHEDULES, FrameType.REQUEST_SCHEDULES),
541
+ (ATTR_PASSWORD, FrameType.REQUEST_PASSWORD),
542
+ ]
299
543
 
300
544
 
301
545
  @patch("asyncio.Queue.put_nowait")