pywmswebcontrolpro 0.1.2__tar.gz → 0.2.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.
Files changed (36) hide show
  1. pywmswebcontrolpro-0.2.0/CHANGELOG.md +55 -0
  2. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/PKG-INFO +51 -5
  3. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/README.md +49 -4
  4. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/mypy.ini +1 -0
  5. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pyproject.toml +3 -0
  6. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/action.py +137 -20
  7. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/const.py +13 -4
  8. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/destination.py +26 -16
  9. pywmswebcontrolpro-0.2.0/pywmswebcontrolpro/exceptions.py +24 -0
  10. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/room.py +7 -4
  11. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/scene.py +4 -2
  12. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/store.py +44 -13
  13. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/travel.py +22 -0
  14. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/webcontrol.py +59 -24
  15. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/conftest.py +24 -7
  16. pywmswebcontrolpro-0.2.0/tests/test_client.py +277 -0
  17. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/test_refresh.py +19 -5
  18. pywmswebcontrolpro-0.2.0/tests/test_rotation.py +212 -0
  19. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/test_settings.py +96 -2
  20. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/.github/workflows/release.yaml +0 -0
  21. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/.github/workflows/validate.yaml +0 -0
  22. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/.gitignore +0 -0
  23. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/.python-version +0 -0
  24. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/LICENSE +0 -0
  25. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pytest.ini +0 -0
  26. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/__init__.py +0 -0
  27. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/py.typed +0 -0
  28. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/pywmswebcontrolpro/refresh.py +0 -0
  29. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/requirements_lint.txt +0 -0
  30. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/requirements_test.txt +0 -0
  31. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/ruff.toml +0 -0
  32. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/simulator/simulator.py +0 -0
  33. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/__init__.py +0 -0
  34. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/test_configuration.py +0 -0
  35. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/test_import.py +0 -0
  36. {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.0}/tests/test_travel.py +0 -0
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 (unreleased)
4
+
5
+ Breaking changes:
6
+
7
+ - Requests raise the errors of the library (`WebControlProConnectionError`,
8
+ `WebControlProResponseError`) instead of `aiohttp.ClientError` and `TimeoutError`.
9
+ - An action or a scene that the gateway rejects raises `WebControlProCommandError`
10
+ instead of returning the answer with its `errors`.
11
+ - `Destination.refresh()` does not ask again by default when the radio is busy
12
+ (`retries=0`, was 2).
13
+ - A rotation action whose limits the hub reports as -127 and 127 uses -75 and 75
14
+ (`minValue`, `maxValue`, `rotation_range`). `wms__minValue`, `wms__maxValue` and
15
+ `reported_rotation_range` return the limits of the hub.
16
+ - Actions of different destinations with the same id are no longer equal.
17
+
18
+ Added:
19
+
20
+ - Workaround for the firmware bug of the rotation limits in the library: default
21
+ limits, learning from a larger measured rotation, `Action.set_rotation_range`,
22
+ `Action.reset_rotation_range`, `Action.rotation_to_tilt` and
23
+ `Action.tilt_to_rotation`. The conversion is linear and sends whole numbers within
24
+ the limits.
25
+ - Unknown enumeration values of a newer firmware become `Unknown`, unknown fields of
26
+ the configuration are ignored.
27
+
28
+ Fixed:
29
+
30
+ - The HTTP status of an answer is checked, an answer that is no JSON object is an
31
+ error of the library.
32
+ - A configuration that is not understood leaves the known destinations unchanged.
33
+ - A status with an error other than radio busy counts as `error` instead of `empty`
34
+ and does not replace the last status.
35
+ - A change during the first load of the stored file no longer replaces the file with
36
+ defaults. A change during a write is stored with the next sync.
37
+ - The stored file is written through a temporary file of its own and synced to disk.
38
+ A failed write is logged and tried again, a file with a broken encoding or an
39
+ invalid stored position is ignored.
40
+ - Ids of destinations and actions must be numbers, they are part of a file path.
41
+
42
+ ## 0.1.2
43
+
44
+ - Keep known destinations when the configuration is read again.
45
+
46
+ ## 0.1.1
47
+
48
+ - Docstrings, type hints and `py.typed`.
49
+
50
+ ## 0.1.0
51
+
52
+ - First release as `pywmswebcontrolpro`, forked from `pywmspro` by Marc Hoersken.
53
+ - Refresh outcome and counters per destination, settings, movement model and stored
54
+ state per drive action.
55
+ - The spacing of status requests is a constructor argument.
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pywmswebcontrolpro
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: Python library for the Warema WMS WebControl pro API
5
5
  Author-email: Marc Hoersken <info@marc-hoersken.de>
6
+ Maintainer: zomtec
6
7
  License-Expression: Apache-2.0
7
8
  License-File: LICENSE
8
9
  Keywords: warema,webcontrol,wms
@@ -32,11 +33,11 @@ See the main section in `pywmswebcontrolpro/webcontrol.py`.
32
33
 
33
34
  ## Status refresh
34
35
 
35
- `Destination.refresh(retries=2)` requests the status of a destination and returns a
36
+ `Destination.refresh()` requests the status of a destination once and returns a
36
37
  `RefreshOutcome` with the result (`ok`, `busy`, `empty` or `error`) and the values
37
- of the actions. Only a "radio busy" answer is retried; with `retries=0` exactly one
38
- request is sent. On any failure the previous values stay unchanged. The outcome is
39
- truthy only for `ok`.
38
+ of the actions. A "radio busy" answer is not retried by default, because every request
39
+ adds traffic to the radio channel; `retries=2` asks up to two more times. On any
40
+ failure the previous values stay unchanged. The outcome is truthy only for `ok`.
40
41
 
41
42
  `WebControlPro(request_spacing=...)` sets the minimum pause between two status requests
42
43
  to the hub (default 0.5 seconds).
@@ -46,6 +47,29 @@ Failed refreshes are counted per destination (`Destination.stats`, also part of
46
47
  failed continuously for `stale_warning_after` (default 24 hours) and once when it
47
48
  delivers data again.
48
49
 
50
+ ## Errors
51
+
52
+ All errors of the library derive from `WebControlProError`
53
+ (`pywmswebcontrolpro.exceptions`):
54
+
55
+ - `WebControlProConnectionError`: the gateway did not answer (connection error or
56
+ timeout of 5 seconds).
57
+ - `WebControlProResponseError`: the gateway answered with an HTTP error or with
58
+ something that is not understood. A configuration that is not understood leaves the
59
+ known destinations unchanged.
60
+ - `WebControlProCommandError`: the gateway rejected an action or a scene, for example
61
+ because the radio channel is busy. `errors` holds the codes of the gateway. A
62
+ rejected command is not sent again.
63
+
64
+ `Destination.refresh()` raises none of them unless `raise_on_error=True` is passed, it
65
+ reports them as result `error`. Fields and enumeration values that a newer firmware
66
+ adds are accepted, an unknown value becomes `Unknown`.
67
+
68
+ ## Security
69
+
70
+ The gateway offers its API only over HTTP without authentication, so the library
71
+ cannot encrypt or authenticate the connection. Run the gateway in a trusted network.
72
+
49
73
  ## Settings, movement model and stored state
50
74
 
51
75
  Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
@@ -68,6 +92,28 @@ independently. After a restart the position is restored from the file and marked
68
92
  `restored` until a measurement arrives. Call `Action.sync()` after commands and
69
93
  measurements to store changes; `Destination.refresh` does it as well.
70
94
 
95
+ ## Rotation limits of slat drives (firmware bug)
96
+
97
+ The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
98
+ from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
99
+ (rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
100
+ not been announced.
101
+
102
+ The library works around it in `pywmswebcontrolpro/action.py`:
103
+
104
+ - While the hub reports exactly -127 and 127 for a rotation action, `Action.rotation_range`
105
+ is -75 to 75. `Action.reported_rotation_range` returns the limits of the hub.
106
+ - A rotation that is measured beyond the range in use widens it. The limits of the hub
107
+ themselves (-127 and 127) are never learned.
108
+ - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
109
+ returns to the default. Both are stored in the file of the action.
110
+ - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
111
+ use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
112
+ rotation that is sent is a whole number within the limits.
113
+
114
+ The workaround ends by itself when a firmware reports other limits. It can be removed
115
+ from the library once such a firmware is available.
116
+
71
117
  ## Development
72
118
 
73
119
  ```bash
@@ -19,11 +19,11 @@ See the main section in `pywmswebcontrolpro/webcontrol.py`.
19
19
 
20
20
  ## Status refresh
21
21
 
22
- `Destination.refresh(retries=2)` requests the status of a destination and returns a
22
+ `Destination.refresh()` requests the status of a destination once and returns a
23
23
  `RefreshOutcome` with the result (`ok`, `busy`, `empty` or `error`) and the values
24
- of the actions. Only a "radio busy" answer is retried; with `retries=0` exactly one
25
- request is sent. On any failure the previous values stay unchanged. The outcome is
26
- truthy only for `ok`.
24
+ of the actions. A "radio busy" answer is not retried by default, because every request
25
+ adds traffic to the radio channel; `retries=2` asks up to two more times. On any
26
+ failure the previous values stay unchanged. The outcome is truthy only for `ok`.
27
27
 
28
28
  `WebControlPro(request_spacing=...)` sets the minimum pause between two status requests
29
29
  to the hub (default 0.5 seconds).
@@ -33,6 +33,29 @@ Failed refreshes are counted per destination (`Destination.stats`, also part of
33
33
  failed continuously for `stale_warning_after` (default 24 hours) and once when it
34
34
  delivers data again.
35
35
 
36
+ ## Errors
37
+
38
+ All errors of the library derive from `WebControlProError`
39
+ (`pywmswebcontrolpro.exceptions`):
40
+
41
+ - `WebControlProConnectionError`: the gateway did not answer (connection error or
42
+ timeout of 5 seconds).
43
+ - `WebControlProResponseError`: the gateway answered with an HTTP error or with
44
+ something that is not understood. A configuration that is not understood leaves the
45
+ known destinations unchanged.
46
+ - `WebControlProCommandError`: the gateway rejected an action or a scene, for example
47
+ because the radio channel is busy. `errors` holds the codes of the gateway. A
48
+ rejected command is not sent again.
49
+
50
+ `Destination.refresh()` raises none of them unless `raise_on_error=True` is passed, it
51
+ reports them as result `error`. Fields and enumeration values that a newer firmware
52
+ adds are accepted, an unknown value becomes `Unknown`.
53
+
54
+ ## Security
55
+
56
+ The gateway offers its API only over HTTP without authentication, so the library
57
+ cannot encrypt or authenticate the connection. Run the gateway in a trusted network.
58
+
36
59
  ## Settings, movement model and stored state
37
60
 
38
61
  Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
@@ -55,6 +78,28 @@ independently. After a restart the position is restored from the file and marked
55
78
  `restored` until a measurement arrives. Call `Action.sync()` after commands and
56
79
  measurements to store changes; `Destination.refresh` does it as well.
57
80
 
81
+ ## Rotation limits of slat drives (firmware bug)
82
+
83
+ The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
84
+ from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
85
+ (rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
86
+ not been announced.
87
+
88
+ The library works around it in `pywmswebcontrolpro/action.py`:
89
+
90
+ - While the hub reports exactly -127 and 127 for a rotation action, `Action.rotation_range`
91
+ is -75 to 75. `Action.reported_rotation_range` returns the limits of the hub.
92
+ - A rotation that is measured beyond the range in use widens it. The limits of the hub
93
+ themselves (-127 and 127) are never learned.
94
+ - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
95
+ returns to the default. Both are stored in the file of the action.
96
+ - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
97
+ use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
98
+ rotation that is sent is a whole number within the limits.
99
+
100
+ The workaround ends by itself when a firmware reports other limits. It can be removed
101
+ from the library once such a firmware is available.
102
+
58
103
  ## Development
59
104
 
60
105
  ```bash
@@ -1,5 +1,6 @@
1
1
  [mypy]
2
2
  python_version = 3.14
3
+ strict = True
3
4
  files = pywmswebcontrolpro
4
5
 
5
6
  [mypy-aiohttp.*,aiofiles.*]
@@ -7,6 +7,9 @@ license-files = ["LICENSE"]
7
7
  authors = [
8
8
  { name = "Marc Hoersken", email = "info@marc-hoersken.de" }
9
9
  ]
10
+ maintainers = [
11
+ { name = "zomtec" }
12
+ ]
10
13
  readme = "README.md"
11
14
  repository = "https://github.com/zomtec/pywmswebcontrolpro"
12
15
  keywords = ["warema", "wms", "webcontrol"]
@@ -1,5 +1,6 @@
1
1
  """An action of a destination with its stored settings and movement model."""
2
2
 
3
+ import asyncio
3
4
  import math
4
5
  from dataclasses import asdict, replace
5
6
  from typing import TYPE_CHECKING, Any
@@ -9,8 +10,14 @@ from .const import (
9
10
  WMS_WebControl_pro_API_actionType,
10
11
  WMS_WebControl_pro_API_responseType,
11
12
  )
12
- from .store import STORE_VERSION, ActionSettings, JsonStore, TravelDirection
13
- from .travel import CoverModel, Measurement
13
+ from .store import (
14
+ STORE_VERSION,
15
+ ActionSettings,
16
+ JsonStore,
17
+ TravelDirection,
18
+ valid_percent,
19
+ )
20
+ from .travel import CoverModel, Measurement, rotation_to_tilt, tilt_to_rotation
14
21
 
15
22
  if TYPE_CHECKING:
16
23
  from .destination import Destination
@@ -18,8 +25,23 @@ if TYPE_CHECKING:
18
25
 
19
26
  _STORED_KEYS = frozenset({"version", "overwrites", "settings", "state"})
20
27
 
28
+ # Firmware bug of the WMS WebControl pro: the hub reports the rotation limits
29
+ # of slat drives as -127 and 127, the drives turn from -75 to 75. Warema knows
30
+ # the bug and has not fixed it. While the hub reports exactly these limits,
31
+ # -75 and 75 are used instead. A rotation measured beyond them widens the
32
+ # range, and the user can overwrite it. The workaround ends by itself when a
33
+ # firmware reports other limits and can then be removed.
34
+ ROTATION_LIMIT_REPORTED_BY_BUG = 127
35
+ ROTATION_LIMIT_DEFAULT = 75
36
+ _MIN_VALUE = "minValue"
37
+ _MAX_VALUE = "maxValue"
38
+
39
+
40
+ def _is_number(value: Any) -> bool:
41
+ return isinstance(value, int | float) and not isinstance(value, bool)
42
+
21
43
 
22
- class ActionList(list):
44
+ class ActionList(list[dict[str, Any]]):
23
45
  """Actions that are sent to the gateway with one request."""
24
46
 
25
47
  def __init__(self, control: WebControlPro) -> None:
@@ -55,17 +77,20 @@ class Action:
55
77
  ) -> None:
56
78
  """Create the action from the configuration of the gateway."""
57
79
  self._dest = dest
58
- self._id = id
59
- self._persist = (dest._persist / f"{id}.json") if dest._persist else None
80
+ # The id becomes part of a file path, so it must be a number.
81
+ self._id = int(id)
82
+ self._persist = (dest._persist / f"{self._id}.json") if dest._persist else None
60
83
  self._store = JsonStore(self._persist)
61
84
  self._actionType = WMS_WebControl_pro_API_actionType(actionType)
62
85
  self._actionDescription = WMS_WebControl_pro_API_actionDescription(
63
86
  actionDescription
64
87
  )
65
88
  self._attrs = kwargs
89
+ self._defaults = self._rotation_defaults()
66
90
  self._params: dict[str, Any] = {}
67
91
  self._overwrites: dict[str, Any] = {}
68
92
  self._needs_load = True
93
+ self._load_lock = asyncio.Lock()
69
94
  self._needs_save = False
70
95
  self._extra: dict[str, Any] = {}
71
96
  self._settings = ActionSettings()
@@ -79,10 +104,14 @@ class Action:
79
104
  return f"<Action {self.id}: {self} ({self.actionType.name})>"
80
105
 
81
106
  def __eq__(self, other: object) -> bool:
82
- return isinstance(other, Action) and self.id == other.id
107
+ return (
108
+ isinstance(other, Action)
109
+ and self._dest == other._dest
110
+ and self.id == other.id
111
+ )
83
112
 
84
113
  def __hash__(self) -> int:
85
- return hash(self.id)
114
+ return hash((self._dest.id, self.id))
86
115
 
87
116
  # --- Properties ---
88
117
 
@@ -108,8 +137,41 @@ class Action:
108
137
 
109
138
  # --- Private methods ---
110
139
 
111
- def _update_params(self, value: dict) -> None:
140
+ def _rotation_defaults(self) -> dict[str, Any]:
141
+ if (
142
+ self._actionType is WMS_WebControl_pro_API_actionType.Rotation
143
+ and self._attrs.get(_MIN_VALUE) == -ROTATION_LIMIT_REPORTED_BY_BUG
144
+ and self._attrs.get(_MAX_VALUE) == ROTATION_LIMIT_REPORTED_BY_BUG
145
+ ):
146
+ return {
147
+ _MIN_VALUE: -ROTATION_LIMIT_DEFAULT,
148
+ _MAX_VALUE: ROTATION_LIMIT_DEFAULT,
149
+ }
150
+ return {}
151
+
152
+ def _update_params(self, value: dict[str, Any]) -> None:
112
153
  self._params.update(value)
154
+ self._learn_rotation_range(value.get("rotation"))
155
+
156
+ def _learn_rotation_range(self, rotation: Any) -> None:
157
+ if (
158
+ self._actionType is not WMS_WebControl_pro_API_actionType.Rotation
159
+ or not _is_number(rotation)
160
+ ):
161
+ return
162
+ reported_min, reported_max = self.reported_rotation_range
163
+ if not (_is_number(reported_min) and _is_number(reported_max)):
164
+ return
165
+ # The reported limits themselves are no real position of a drive.
166
+ if not reported_min < rotation < reported_max:
167
+ return
168
+ minimum, maximum = self.rotation_range
169
+ if rotation < minimum:
170
+ self._overwrites[_MIN_VALUE] = rotation
171
+ self._needs_save = True
172
+ elif rotation > maximum:
173
+ self._overwrites[_MAX_VALUE] = rotation
174
+ self._needs_save = True
113
175
 
114
176
  async def _load_persists(self) -> None:
115
177
  data = await self._store.load()
@@ -120,17 +182,22 @@ class Action:
120
182
  self._settings = ActionSettings.from_dict(data.get("settings"))
121
183
  state = data.get("state")
122
184
  if isinstance(state, dict):
185
+ position = valid_percent(state.get("position"))
186
+ tilt = valid_percent(state.get("tilt"))
187
+ target_tilt = valid_percent(state.get("target_tilt"))
123
188
  self.model.restore(
124
- state.get("position"),
125
- state.get("tilt"),
126
- state.get("target_position"),
127
- state.get("target_tilt"),
189
+ position,
190
+ None if tilt is None else int(tilt),
191
+ valid_percent(state.get("target_position")),
192
+ None if target_tilt is None else int(target_tilt),
128
193
  )
129
194
  self._saved_state = self.model.snapshot()
130
195
 
131
196
  async def _save_persists(self) -> None:
132
197
  state = self.model.snapshot()
133
- await self._store.save(
198
+ # Cleared before the write, so a change made during it is stored next.
199
+ self._needs_save = False
200
+ saved = await self._store.save(
134
201
  {
135
202
  **self._extra,
136
203
  "version": STORE_VERSION,
@@ -139,13 +206,18 @@ class Action:
139
206
  "state": state,
140
207
  }
141
208
  )
142
- self._saved_state = state
143
- self._needs_save = False
209
+ if saved:
210
+ self._saved_state = state
211
+ else:
212
+ self._needs_save = True
144
213
 
145
214
  async def _ensure_loaded(self) -> None:
146
- if self._needs_load:
147
- self._needs_load = False
148
- await self._load_persists()
215
+ # The lock makes a second caller wait for the stored data instead of
216
+ # working with the defaults and overwriting the file.
217
+ async with self._load_lock:
218
+ if self._needs_load:
219
+ await self._load_persists()
220
+ self._needs_load = False
149
221
 
150
222
  # --- Public methods ---
151
223
 
@@ -164,6 +236,46 @@ class Action:
164
236
  )
165
237
  await self._save_persists()
166
238
 
239
+ @property
240
+ def reported_rotation_range(self) -> tuple[Any, Any]:
241
+ """Return the rotation limits as the hub reports them."""
242
+ return self._attrs.get(_MIN_VALUE), self._attrs.get(_MAX_VALUE)
243
+
244
+ @property
245
+ def rotation_range(self) -> tuple[float, float]:
246
+ """Return the rotation limits in use, minimum and maximum.
247
+
248
+ An overwrite wins over the default for the firmware bug, which wins
249
+ over the limits of the hub.
250
+ """
251
+ return self.minValue, self.maxValue
252
+
253
+ async def set_rotation_range(
254
+ self, *, minimum: float | None = None, maximum: float | None = None
255
+ ) -> None:
256
+ """Overwrite one or both rotation limits and store them."""
257
+ await self._ensure_loaded()
258
+ if minimum is not None:
259
+ self._overwrites[_MIN_VALUE] = minimum
260
+ if maximum is not None:
261
+ self._overwrites[_MAX_VALUE] = maximum
262
+ await self._save_persists()
263
+
264
+ async def reset_rotation_range(self) -> None:
265
+ """Remove the overwritten rotation limits and store that."""
266
+ await self._ensure_loaded()
267
+ self._overwrites.pop(_MIN_VALUE, None)
268
+ self._overwrites.pop(_MAX_VALUE, None)
269
+ await self._save_persists()
270
+
271
+ def rotation_to_tilt(self, rotation: float) -> int:
272
+ """Convert a rotation to a tilt (0 closed, 100 open) with the limits in use."""
273
+ return rotation_to_tilt(rotation, *self.rotation_range)
274
+
275
+ def tilt_to_rotation(self, tilt: float) -> int:
276
+ """Convert a tilt (0 closed, 100 open) to a rotation with the limits in use."""
277
+ return tilt_to_rotation(tilt, *self.rotation_range)
278
+
167
279
  def start_move(self, now: float, target: float, tilt: int | None = None) -> float:
168
280
  """Handle an accepted drive command with the stored travel times.
169
281
 
@@ -193,10 +305,14 @@ class Action:
193
305
  await self._save_persists()
194
306
 
195
307
  def __getattr__(self, name: str) -> Any:
308
+ if name.startswith("_"):
309
+ raise AttributeError(name)
196
310
  if name in self._overwrites:
197
311
  return self._overwrites[name]
198
312
  if name.startswith("wms__"):
199
- name = name[5:]
313
+ return self._attrs.get(name[5:])
314
+ if name in self._defaults:
315
+ return self._defaults[name]
200
316
  return self._attrs.get(name)
201
317
 
202
318
  def __getitem__(self, name: str) -> Any:
@@ -241,7 +357,7 @@ class Action:
241
357
  responseType=responseType,
242
358
  )
243
359
 
244
- def diag(self) -> dict:
360
+ def diag(self) -> dict[str, Any]:
245
361
  """Return the action for the diagnostics."""
246
362
  return {
247
363
  "id": self.id,
@@ -250,6 +366,7 @@ class Action:
250
366
  "attrs": self._attrs,
251
367
  "params": self._params,
252
368
  "overwrites": self._overwrites,
369
+ "defaults": self._defaults,
253
370
  "settings": asdict(self._settings),
254
371
  "model": {
255
372
  **self.model.snapshot(),
@@ -1,6 +1,7 @@
1
1
  """Constants and enumerations of the WMS WebControl pro API."""
2
2
 
3
3
  from enum import IntEnum
4
+ from typing import Self
4
5
 
5
6
  WMS_WebControl_pro_API_protocolVersion = "1.0"
6
7
  WMS_WebControl_pro_API_source = 2
@@ -12,7 +13,15 @@ WMS_WebControl_pro_API_command_action = "action"
12
13
  WMS_WebControl_pro_API_command_sceneActions = "sceneActions"
13
14
 
14
15
 
15
- class WMS_WebControl_pro_API_animationType(IntEnum):
16
+ class _TolerantIntEnum(IntEnum):
17
+ """Enumeration that maps a value of a newer firmware to Unknown."""
18
+
19
+ @classmethod
20
+ def _missing_(cls, value: object) -> Self:
21
+ return cls["Unknown"]
22
+
23
+
24
+ class WMS_WebControl_pro_API_animationType(_TolerantIntEnum):
16
25
  """Kind of device that a destination controls."""
17
26
 
18
27
  VenetianBlind = 0
@@ -25,7 +34,7 @@ class WMS_WebControl_pro_API_animationType(IntEnum):
25
34
  Unknown = 999
26
35
 
27
36
 
28
- class WMS_WebControl_pro_API_actionType(IntEnum):
37
+ class WMS_WebControl_pro_API_actionType(_TolerantIntEnum):
29
38
  """Kind of value or command of an action."""
30
39
 
31
40
  Percentage = 0
@@ -41,7 +50,7 @@ class WMS_WebControl_pro_API_actionType(IntEnum):
41
50
  Unknown = 999
42
51
 
43
52
 
44
- class WMS_WebControl_pro_API_actionDescription(IntEnum):
53
+ class WMS_WebControl_pro_API_actionDescription(_TolerantIntEnum):
45
54
  """Function of an action, for example awning drive or light switch."""
46
55
 
47
56
  AwningDrive = 0
@@ -75,7 +84,7 @@ class WMS_WebControl_pro_API_sceneActionType(IntEnum):
75
84
  Execute = 1
76
85
 
77
86
 
78
- class WMS_WebControl_pro_API_drivingCause(IntEnum):
87
+ class WMS_WebControl_pro_API_drivingCause(_TolerantIntEnum):
79
88
  """Reason why a drive moved last."""
80
89
 
81
90
  _None = 0 # No driving cause
@@ -7,8 +7,6 @@ from collections.abc import Mapping
7
7
  from types import MappingProxyType
8
8
  from typing import TYPE_CHECKING, Any
9
9
 
10
- import aiohttp
11
-
12
10
  from .action import Action
13
11
  from .const import (
14
12
  WMS_WebControl_pro_API_actionDescription,
@@ -16,6 +14,7 @@ from .const import (
16
14
  WMS_WebControl_pro_API_animationType,
17
15
  WMS_WebControl_pro_API_drivingCause,
18
16
  )
17
+ from .exceptions import WebControlProError
19
18
  from .refresh import (
20
19
  ERROR_RADIO_BUSY,
21
20
  RefreshOutcome,
@@ -28,7 +27,8 @@ from .room import Room
28
27
  if TYPE_CHECKING:
29
28
  from .webcontrol import WebControlPro
30
29
 
31
- DEFAULT_REFRESH_RETRIES = 2
30
+ # A busy radio channel is not asked again, every request adds radio traffic.
31
+ DEFAULT_REFRESH_RETRIES = 0
32
32
 
33
33
  _LOGGER = logging.getLogger(__name__)
34
34
 
@@ -43,11 +43,13 @@ class Destination:
43
43
  names: list[str],
44
44
  actions: list[dict[str, Any]],
45
45
  animationType: int,
46
+ **kwargs: Any,
46
47
  ) -> None:
47
48
  self._control = control
48
- self._id = id
49
+ # The id becomes part of a file path, so it must be a number.
50
+ self._id = int(id)
49
51
  self._names = names
50
- self._persist = (control._persist / str(id)) if control._persist else None
52
+ self._persist = (control._persist / str(self._id)) if control._persist else None
51
53
  self._actions = {action["id"]: Action(self, **action) for action in actions}
52
54
  self._animationType = WMS_WebControl_pro_API_animationType(animationType)
53
55
  self._drivingCause = WMS_WebControl_pro_API_drivingCause.Unknown
@@ -87,7 +89,7 @@ class Destination:
87
89
  return self._names[0]
88
90
 
89
91
  @property
90
- def actions(self) -> dict:
92
+ def actions(self) -> dict[int, Action]:
91
93
  """Return the actions of the destination by id."""
92
94
  return self._actions
93
95
 
@@ -115,7 +117,7 @@ class Destination:
115
117
  return not (self._heartbeatError or self._blocking)
116
118
 
117
119
  @property
118
- def status(self) -> Mapping:
120
+ def status(self) -> Mapping[str, Any]:
119
121
  """Return the last status that the gateway answered."""
120
122
  return MappingProxyType(self._status)
121
123
 
@@ -138,7 +140,8 @@ class Destination:
138
140
 
139
141
  With retries=0 exactly one request is sent. On any failure the
140
142
  previously known values stay unchanged. The outcome is counted in
141
- stats instead of being logged for every failure.
143
+ stats instead of being logged for every failure. With raise_on_error
144
+ a WebControlProError of the request is raised instead of counted.
142
145
  """
143
146
  await self.sync()
144
147
 
@@ -149,15 +152,15 @@ class Destination:
149
152
  async def _request_status(
150
153
  self, retries: int, raise_on_error: bool
151
154
  ) -> RefreshOutcome:
152
- status: dict = {}
155
+ status: dict[str, Any] = {}
153
156
  for attempt in range(retries + 1):
154
157
  try:
155
158
  status = await self._control._getStatus(self._id)
156
- except aiohttp.ClientError, TimeoutError:
159
+ except WebControlProError:
157
160
  if raise_on_error:
158
161
  raise
159
162
  return RefreshOutcome(RefreshResult.ERROR)
160
- if ERROR_RADIO_BUSY not in ((status or {}).get("errors") or ()):
163
+ if ERROR_RADIO_BUSY not in (status.get("errors") or ()):
161
164
  break
162
165
  if attempt < retries:
163
166
  await asyncio.sleep(self._control.retry_delay)
@@ -167,13 +170,20 @@ class Destination:
167
170
  if not status:
168
171
  return RefreshOutcome(RefreshResult.EMPTY)
169
172
 
170
- self._status = status
171
- values = self._apply_status(status)
173
+ try:
174
+ values = self._apply_status(status)
175
+ except (AttributeError, KeyError, TypeError) as err:
176
+ _LOGGER.debug("Unexpected status for %s (%s): %r", self, self._id, err)
177
+ return RefreshOutcome(RefreshResult.ERROR)
172
178
  if values is None:
173
- return RefreshOutcome(RefreshResult.EMPTY)
179
+ result = (
180
+ RefreshResult.ERROR if status.get("errors") else RefreshResult.EMPTY
181
+ )
182
+ return RefreshOutcome(result)
183
+ self._status = status
174
184
  return RefreshOutcome(RefreshResult.OK, values)
175
185
 
176
- def _apply_status(self, status: dict) -> dict[int, dict[str, Any]] | None:
186
+ def _apply_status(self, status: dict[str, Any]) -> dict[int, dict[str, Any]] | None:
177
187
  values: dict[int, dict[str, Any]] = {}
178
188
  refreshed = False
179
189
  for detail in status.get("details") or ():
@@ -256,7 +266,7 @@ class Destination:
256
266
  f"and type {type_name} in {self} ({self._id})"
257
267
  )
258
268
 
259
- def diag(self) -> dict:
269
+ def diag(self) -> dict[str, Any]:
260
270
  """Return the destination for the diagnostics."""
261
271
  return {
262
272
  "id": self.id,