pywmswebcontrolpro 0.9.2__tar.gz → 0.10.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.
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/CHANGELOG.md +18 -1
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/PKG-INFO +8 -6
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/README.md +7 -5
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/action.py +9 -6
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/cover.py +17 -2
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/store.py +11 -3
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/travel.py +35 -11
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/webcontrol.py +33 -5
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/conftest.py +1 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_cover.py +24 -3
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_refresh.py +51 -9
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_settings.py +18 -10
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_travel.py +32 -5
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/.gitignore +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/.python-version +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/LICENSE +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/destination.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.0}/tests/test_rotation.py +0 -0
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.10.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
Changed:
|
|
6
|
+
|
|
7
|
+
- The slats have a turn time for each direction, like in the device settings of the
|
|
8
|
+
hub: `Action.set_turn_time(direction, seconds)` with `TravelDirection.OPEN` for a
|
|
9
|
+
turn to the minimum rotation and `TravelDirection.CLOSE` for a turn to the maximum.
|
|
10
|
+
Both are 1.6 seconds by default. `ActionSettings.turn_time(direction)` returns one,
|
|
11
|
+
`CoverModel.start_move` and `CoverModel.set_rotation` take `turn_times` (open,
|
|
12
|
+
close). A turn from an unknown rotation takes the longer full turn time.
|
|
13
|
+
- A status request waits until 2 seconds after the last command to the hub
|
|
14
|
+
(`command_spacing`, `DEFAULT_COMMAND_SPACING`). The hub accepts a command at once and
|
|
15
|
+
sends it on the radio afterwards; a status request right after it was answered with
|
|
16
|
+
radio busy in live tests.
|
|
17
|
+
- A stop within 1 second after a stop of the same cover, with no other command
|
|
18
|
+
between, is not sent again (`TravelSettings.stop_repeat_window`).
|
|
19
|
+
|
|
20
|
+
## 0.9.2
|
|
4
21
|
|
|
5
22
|
Changed:
|
|
6
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pywmswebcontrolpro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Python library for the Warema WMS WebControl pro API
|
|
5
5
|
Author-email: Marc Hoersken <info@marc-hoersken.de>
|
|
6
6
|
Maintainer: zomtec
|
|
@@ -99,7 +99,7 @@ has a directory of its own, named by its id, with two files:
|
|
|
99
99
|
action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
|
|
100
100
|
are the travel times for a full drive, open and close, in seconds
|
|
101
101
|
(`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
|
|
102
|
-
of the rotation limits and the turn
|
|
102
|
+
of the rotation limits and the turn times of the slats (`Action.set_turn_time`, see
|
|
103
103
|
below). Only values that differ from the defaults are stored.
|
|
104
104
|
- `state.json`: the last known percentage and rotation of a drive action and the
|
|
105
105
|
target of a running drive.
|
|
@@ -210,10 +210,12 @@ A drive of a slat drive has three phases in the model, as the hub runs them: the
|
|
|
210
210
|
turn to the minimum rotation before the cover drives up and to the maximum before it
|
|
211
211
|
drives down, then the cover drives, then the slats turn to the rotation sent with the
|
|
212
212
|
drive; without one they stay at the rotation of the direction. A rotation alone turns
|
|
213
|
-
the slats in the same way.
|
|
214
|
-
|
|
215
|
-
rotation, `
|
|
216
|
-
|
|
213
|
+
the slats in the same way. Like in the device settings of the hub, the rotation action
|
|
214
|
+
has a turn time for each direction over the whole rotation range: `OPEN` for a turn to
|
|
215
|
+
the minimum rotation, `CLOSE` for a turn to the maximum (`Action.settings.turn_time`,
|
|
216
|
+
1.6 seconds each by default, `Action.set_turn_time` changes one, 0 turns at once). A
|
|
217
|
+
turn takes the time of its direction in proportion to the angle, from an unknown
|
|
218
|
+
rotation the longer of the two full turn times. Measurements are ignored until the
|
|
217
219
|
whole movement has ended, and the settle poll follows 2 seconds after it, so it does
|
|
218
220
|
not catch slats that still turn. A stop leaves percentage and rotation where they are.
|
|
219
221
|
|
|
@@ -85,7 +85,7 @@ has a directory of its own, named by its id, with two files:
|
|
|
85
85
|
action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
|
|
86
86
|
are the travel times for a full drive, open and close, in seconds
|
|
87
87
|
(`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
|
|
88
|
-
of the rotation limits and the turn
|
|
88
|
+
of the rotation limits and the turn times of the slats (`Action.set_turn_time`, see
|
|
89
89
|
below). Only values that differ from the defaults are stored.
|
|
90
90
|
- `state.json`: the last known percentage and rotation of a drive action and the
|
|
91
91
|
target of a running drive.
|
|
@@ -196,10 +196,12 @@ A drive of a slat drive has three phases in the model, as the hub runs them: the
|
|
|
196
196
|
turn to the minimum rotation before the cover drives up and to the maximum before it
|
|
197
197
|
drives down, then the cover drives, then the slats turn to the rotation sent with the
|
|
198
198
|
drive; without one they stay at the rotation of the direction. A rotation alone turns
|
|
199
|
-
the slats in the same way.
|
|
200
|
-
|
|
201
|
-
rotation, `
|
|
202
|
-
|
|
199
|
+
the slats in the same way. Like in the device settings of the hub, the rotation action
|
|
200
|
+
has a turn time for each direction over the whole rotation range: `OPEN` for a turn to
|
|
201
|
+
the minimum rotation, `CLOSE` for a turn to the maximum (`Action.settings.turn_time`,
|
|
202
|
+
1.6 seconds each by default, `Action.set_turn_time` changes one, 0 turns at once). A
|
|
203
|
+
turn takes the time of its direction in proportion to the angle, from an unknown
|
|
204
|
+
rotation the longer of the two full turn times. Measurements are ignored until the
|
|
203
205
|
whole movement has ended, and the settle poll follows 2 seconds after it, so it does
|
|
204
206
|
not catch slats that still turn. A stop leaves percentage and rotation where they are.
|
|
205
207
|
|
|
@@ -205,14 +205,17 @@ class Action:
|
|
|
205
205
|
)
|
|
206
206
|
await self.sync()
|
|
207
207
|
|
|
208
|
-
async def set_turn_time(self, seconds: float) -> None:
|
|
209
|
-
"""Store the
|
|
208
|
+
async def set_turn_time(self, direction: TravelDirection, seconds: float) -> None:
|
|
209
|
+
"""Store the time of the slats over the whole rotation range in seconds.
|
|
210
210
|
|
|
211
|
-
|
|
211
|
+
OPEN is the turn to the minimum rotation, CLOSE the turn to the
|
|
212
|
+
maximum. 0 turns the slats at once in the movement model.
|
|
212
213
|
"""
|
|
213
214
|
if not (math.isfinite(seconds) and seconds >= 0):
|
|
214
215
|
raise ValueError(f"Turn time must be a number >= 0: {seconds}")
|
|
215
|
-
self._settings = replace(
|
|
216
|
+
self._settings = replace(
|
|
217
|
+
self._settings, **{f"turn_time_{direction.value}": float(seconds)}
|
|
218
|
+
)
|
|
216
219
|
await self.sync()
|
|
217
220
|
|
|
218
221
|
@property
|
|
@@ -265,7 +268,7 @@ class Action:
|
|
|
265
268
|
rotation: int | None = None,
|
|
266
269
|
*,
|
|
267
270
|
rotation_range: tuple[float, float] | None = None,
|
|
268
|
-
|
|
271
|
+
turn_times: tuple[float, float] = (0.0, 0.0),
|
|
269
272
|
) -> float:
|
|
270
273
|
"""Handle an accepted drive command to a percentage with the stored travel times.
|
|
271
274
|
|
|
@@ -279,7 +282,7 @@ class Action:
|
|
|
279
282
|
self._settings.travel_time(TravelDirection.CLOSE),
|
|
280
283
|
rotation,
|
|
281
284
|
rotation_range=rotation_range,
|
|
282
|
-
|
|
285
|
+
turn_times=turn_times,
|
|
283
286
|
)
|
|
284
287
|
|
|
285
288
|
def apply_measurement(
|
|
@@ -19,6 +19,7 @@ from .const import (
|
|
|
19
19
|
WMS_WebControl_pro_API_actionType,
|
|
20
20
|
WMS_WebControl_pro_API_responseType,
|
|
21
21
|
)
|
|
22
|
+
from .store import TravelDirection
|
|
22
23
|
from .travel import CoverModel, Measurement
|
|
23
24
|
|
|
24
25
|
if TYPE_CHECKING:
|
|
@@ -45,6 +46,7 @@ class Cover:
|
|
|
45
46
|
self._drive = drive
|
|
46
47
|
self._rotation = rotation
|
|
47
48
|
self._lock: asyncio.Lock = dest._command_lock
|
|
49
|
+
self._stopped_at: float | None = None
|
|
48
50
|
|
|
49
51
|
def __str__(self) -> str:
|
|
50
52
|
"""Return the destination and the drive for logs."""
|
|
@@ -139,10 +141,19 @@ class Cover:
|
|
|
139
141
|
WMS_WebControl_pro_API_actionType.Stop,
|
|
140
142
|
)
|
|
141
143
|
async with self._lock:
|
|
144
|
+
now = monotonic()
|
|
145
|
+
if (
|
|
146
|
+
self._stopped_at is not None
|
|
147
|
+
and now - self._stopped_at <= self.model.settings.stop_repeat_window
|
|
148
|
+
):
|
|
149
|
+
_LOGGER.debug("%s: stop just sent, not sent again", self)
|
|
150
|
+
return self.model.settings.settle_after_stop
|
|
142
151
|
await action.prep()(
|
|
143
152
|
responseType=WMS_WebControl_pro_API_responseType.Detailed
|
|
144
153
|
)
|
|
145
|
-
|
|
154
|
+
now = monotonic()
|
|
155
|
+
self._stopped_at = now
|
|
156
|
+
delay = self.model.stop(now)
|
|
146
157
|
_LOGGER.debug("%s: stopped, poll in %.1f s, %r", self, delay, self.model)
|
|
147
158
|
await self._drive.sync()
|
|
148
159
|
return delay
|
|
@@ -158,7 +169,10 @@ class Cover:
|
|
|
158
169
|
return {}
|
|
159
170
|
return {
|
|
160
171
|
"rotation_range": self._rotation.rotation_range,
|
|
161
|
-
"
|
|
172
|
+
"turn_times": (
|
|
173
|
+
self._rotation.settings.turn_time(TravelDirection.OPEN),
|
|
174
|
+
self._rotation.settings.turn_time(TravelDirection.CLOSE),
|
|
175
|
+
),
|
|
162
176
|
}
|
|
163
177
|
|
|
164
178
|
def _rotation_for_move(self, percentage: float) -> int | None:
|
|
@@ -207,6 +221,7 @@ class Cover:
|
|
|
207
221
|
return delay
|
|
208
222
|
|
|
209
223
|
async def _send(self, percentage: float | None, rotation: int | None) -> None:
|
|
224
|
+
self._stopped_at = None
|
|
210
225
|
actions = ActionList(self._dest._control)
|
|
211
226
|
if percentage is not None:
|
|
212
227
|
actions += self._drive.prep(percentage=round(percentage))
|
|
@@ -42,13 +42,15 @@ class ActionSettings:
|
|
|
42
42
|
|
|
43
43
|
A drive action has the travel times of a full drive, 0 means unknown and
|
|
44
44
|
the target of a drive is then taken over at once. A rotation action has
|
|
45
|
-
the turn
|
|
46
|
-
|
|
45
|
+
the turn times of the slats over the whole rotation range, 0 turns them at
|
|
46
|
+
once. Like the hub, a turn to the minimum rotation, the direction of
|
|
47
|
+
opening, and a turn to the maximum have a time each.
|
|
47
48
|
"""
|
|
48
49
|
|
|
49
50
|
travel_time_open: float = 0.0
|
|
50
51
|
travel_time_close: float = 0.0
|
|
51
|
-
|
|
52
|
+
turn_time_open: float = DEFAULT_TURN_TIME
|
|
53
|
+
turn_time_close: float = DEFAULT_TURN_TIME
|
|
52
54
|
|
|
53
55
|
def travel_time(self, direction: TravelDirection) -> float:
|
|
54
56
|
"""Return the travel time of a full drive in seconds."""
|
|
@@ -56,6 +58,12 @@ class ActionSettings:
|
|
|
56
58
|
return self.travel_time_open
|
|
57
59
|
return self.travel_time_close
|
|
58
60
|
|
|
61
|
+
def turn_time(self, direction: TravelDirection) -> float:
|
|
62
|
+
"""Return the time of a turn over the whole rotation range in seconds."""
|
|
63
|
+
if direction is TravelDirection.OPEN:
|
|
64
|
+
return self.turn_time_open
|
|
65
|
+
return self.turn_time_close
|
|
66
|
+
|
|
59
67
|
def changed(self) -> dict[str, float]:
|
|
60
68
|
"""Return the settings that differ from the defaults."""
|
|
61
69
|
default = type(self)()
|
|
@@ -39,6 +39,9 @@ class TravelSettings:
|
|
|
39
39
|
# counts as running only this long. Automations and scenes send their
|
|
40
40
|
# commands right after each other.
|
|
41
41
|
combine_window_untimed: float = 0.5
|
|
42
|
+
# A second stop this soon after a stop, with no command between, is not
|
|
43
|
+
# sent again: the hub already stops, it would only add radio traffic.
|
|
44
|
+
stop_repeat_window: float = 1.0
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
@dataclass(frozen=True)
|
|
@@ -151,6 +154,16 @@ def turn_duration(
|
|
|
151
154
|
return turn_time * min(1.0, abs(end - start) / span)
|
|
152
155
|
|
|
153
156
|
|
|
157
|
+
def _turn_time(start: int | None, end: int, turn_times: tuple[float, float]) -> float:
|
|
158
|
+
"""Return the turn time of the direction, the longer one from an unknown start.
|
|
159
|
+
|
|
160
|
+
turn_times are the times to the minimum and to the maximum rotation.
|
|
161
|
+
"""
|
|
162
|
+
if start is None:
|
|
163
|
+
return max(turn_times)
|
|
164
|
+
return turn_times[0] if end < start else turn_times[1]
|
|
165
|
+
|
|
166
|
+
|
|
154
167
|
class CoverModel:
|
|
155
168
|
"""Displayed state of one cover in the units of the hub."""
|
|
156
169
|
|
|
@@ -303,7 +316,7 @@ class CoverModel:
|
|
|
303
316
|
rotation: int | None = None,
|
|
304
317
|
*,
|
|
305
318
|
rotation_range: tuple[float, float] | None = None,
|
|
306
|
-
|
|
319
|
+
turn_times: tuple[float, float] = (0.0, 0.0),
|
|
307
320
|
) -> float:
|
|
308
321
|
"""Handle an accepted drive command to a percentage.
|
|
309
322
|
|
|
@@ -311,8 +324,8 @@ class CoverModel:
|
|
|
311
324
|
rotation range of slats, the slats first turn to the limit of the
|
|
312
325
|
direction, the minimum up and the maximum down, then the cover drives,
|
|
313
326
|
then the slats turn to the rotation for the end; without one they stay
|
|
314
|
-
at the limit.
|
|
315
|
-
the maximum rotation.
|
|
327
|
+
at the limit. turn_times are the times of the slats over the whole
|
|
328
|
+
rotation range, to the minimum and to the maximum rotation.
|
|
316
329
|
|
|
317
330
|
Returns the delay in seconds until the settle poll.
|
|
318
331
|
"""
|
|
@@ -336,7 +349,7 @@ class CoverModel:
|
|
|
336
349
|
self.percentage = target
|
|
337
350
|
if rotation is None:
|
|
338
351
|
return self.settings.settle_rotation
|
|
339
|
-
return self._turn(now, rotation, rotation_range,
|
|
352
|
+
return self._turn(now, rotation, rotation_range, turn_times)
|
|
340
353
|
|
|
341
354
|
opening = target < start
|
|
342
355
|
drive_rotation: int | None = None
|
|
@@ -345,11 +358,17 @@ class CoverModel:
|
|
|
345
358
|
limit = rotation_range[0] if opening else rotation_range[1]
|
|
346
359
|
drive_rotation = math.floor(limit + 0.5)
|
|
347
360
|
first_turn = turn_duration(
|
|
348
|
-
self.rotation,
|
|
361
|
+
self.rotation,
|
|
362
|
+
drive_rotation,
|
|
363
|
+
rotation_range,
|
|
364
|
+
_turn_time(self.rotation, drive_rotation, turn_times),
|
|
349
365
|
)
|
|
350
366
|
if rotation is not None:
|
|
351
367
|
last_turn = turn_duration(
|
|
352
|
-
drive_rotation,
|
|
368
|
+
drive_rotation,
|
|
369
|
+
rotation,
|
|
370
|
+
rotation_range,
|
|
371
|
+
_turn_time(drive_rotation, rotation, turn_times),
|
|
353
372
|
)
|
|
354
373
|
full_time = time_open if opening else time_close
|
|
355
374
|
if full_time <= 0:
|
|
@@ -382,29 +401,34 @@ class CoverModel:
|
|
|
382
401
|
rotation: int,
|
|
383
402
|
*,
|
|
384
403
|
rotation_range: tuple[float, float] | None = None,
|
|
385
|
-
|
|
404
|
+
turn_times: tuple[float, float] = (0.0, 0.0),
|
|
386
405
|
) -> float:
|
|
387
406
|
"""Handle an accepted rotation-only command, it ends a running drive.
|
|
388
407
|
|
|
389
|
-
With the rotation range and the turn
|
|
408
|
+
With the rotation range and the turn times the slats turn over time.
|
|
390
409
|
"""
|
|
391
410
|
self.advance(now)
|
|
392
411
|
self._motion = None
|
|
393
412
|
self._forget_commands()
|
|
394
413
|
self.source = PositionSource.CALCULATED
|
|
395
|
-
return self._turn(now, rotation, rotation_range,
|
|
414
|
+
return self._turn(now, rotation, rotation_range, turn_times)
|
|
396
415
|
|
|
397
416
|
def _turn(
|
|
398
417
|
self,
|
|
399
418
|
now: float,
|
|
400
419
|
rotation: int,
|
|
401
420
|
rotation_range: tuple[float, float] | None,
|
|
402
|
-
|
|
421
|
+
turn_times: tuple[float, float],
|
|
403
422
|
) -> float:
|
|
404
423
|
duration = (
|
|
405
424
|
0.0
|
|
406
425
|
if rotation_range is None or self.percentage is None
|
|
407
|
-
else turn_duration(
|
|
426
|
+
else turn_duration(
|
|
427
|
+
self.rotation,
|
|
428
|
+
rotation,
|
|
429
|
+
rotation_range,
|
|
430
|
+
_turn_time(self.rotation, rotation, turn_times),
|
|
431
|
+
)
|
|
408
432
|
)
|
|
409
433
|
if duration <= 0 or self.percentage is None:
|
|
410
434
|
self.rotation = rotation
|
|
@@ -40,6 +40,14 @@ from .store import HubStore
|
|
|
40
40
|
DEFAULT_STALE_WARNING_AFTER = timedelta(hours=24)
|
|
41
41
|
DEFAULT_RETRY_DELAY = 1.0
|
|
42
42
|
DEFAULT_REQUEST_SPACING = 0.5
|
|
43
|
+
# The hub accepts a command at once and sends it on the radio afterwards. A
|
|
44
|
+
# status request right after a command was answered with radio busy in live
|
|
45
|
+
# tests (1.3 s, error 327685), so status requests wait this long after the
|
|
46
|
+
# last command.
|
|
47
|
+
DEFAULT_COMMAND_SPACING = 2.0
|
|
48
|
+
_RADIO_COMMANDS = frozenset(
|
|
49
|
+
{WMS_WebControl_pro_API_command_action, WMS_WebControl_pro_API_command_sceneActions}
|
|
50
|
+
)
|
|
43
51
|
|
|
44
52
|
|
|
45
53
|
_LOGGER = logging.getLogger(__name__)
|
|
@@ -73,6 +81,7 @@ class WebControlPro:
|
|
|
73
81
|
stale_warning_after: timedelta = DEFAULT_STALE_WARNING_AFTER,
|
|
74
82
|
retry_delay: float = DEFAULT_RETRY_DELAY,
|
|
75
83
|
request_spacing: float = DEFAULT_REQUEST_SPACING,
|
|
84
|
+
command_spacing: float | None = None,
|
|
76
85
|
stats_window: timedelta = timedelta(seconds=DEFAULT_STATS_WINDOW),
|
|
77
86
|
) -> None:
|
|
78
87
|
"""Create a client.
|
|
@@ -82,7 +91,9 @@ class WebControlPro:
|
|
|
82
91
|
sets how long a destination may stay silent before a warning is
|
|
83
92
|
logged, retry_delay the pause in seconds between retries after a
|
|
84
93
|
radio busy answer and request_spacing the minimum pause in seconds
|
|
85
|
-
between two status requests
|
|
94
|
+
between two status requests, command_spacing the minimum pause in
|
|
95
|
+
seconds between a command and the next status request, by default
|
|
96
|
+
DEFAULT_COMMAND_SPACING. stats_window is the time that the recent
|
|
86
97
|
success rate of the statistics looks back.
|
|
87
98
|
"""
|
|
88
99
|
self.stale_warning_after = stale_warning_after
|
|
@@ -92,6 +103,10 @@ class WebControlPro:
|
|
|
92
103
|
self._status_lock = asyncio.Lock()
|
|
93
104
|
self.request_spacing = request_spacing
|
|
94
105
|
self._status_last = time.monotonic() - self.request_spacing
|
|
106
|
+
self.command_spacing = (
|
|
107
|
+
DEFAULT_COMMAND_SPACING if command_spacing is None else command_spacing
|
|
108
|
+
)
|
|
109
|
+
self._command_last = time.monotonic() - self.command_spacing
|
|
95
110
|
self._host = host
|
|
96
111
|
self._control = f"http://{host}/commonCommand"
|
|
97
112
|
self._session = session
|
|
@@ -115,7 +130,11 @@ class WebControlPro:
|
|
|
115
130
|
async with self._common_lock:
|
|
116
131
|
_LOGGER.debug("Request to %s: %s", self._host, data)
|
|
117
132
|
started = time.monotonic()
|
|
118
|
-
|
|
133
|
+
try:
|
|
134
|
+
answer = await self._post(command, data)
|
|
135
|
+
finally:
|
|
136
|
+
if command in _RADIO_COMMANDS:
|
|
137
|
+
self._command_last = time.monotonic()
|
|
119
138
|
elapsed = time.monotonic() - started
|
|
120
139
|
if command == WMS_WebControl_pro_API_command_getConfiguration:
|
|
121
140
|
_LOGGER.debug("Answer to %s received", command)
|
|
@@ -160,9 +179,10 @@ class WebControlPro:
|
|
|
160
179
|
async def _getStatus(self, destinationId: int) -> tuple[Any, float]:
|
|
161
180
|
"""Return the status answer and the seconds the hub took for it."""
|
|
162
181
|
async with self._status_lock:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
182
|
+
# A command can arrive while the request waits, so check again.
|
|
183
|
+
while (wait := self._status_wait()) > 0:
|
|
184
|
+
_LOGGER.debug("Status request for %s waits %.2f s", destinationId, wait)
|
|
185
|
+
await asyncio.sleep(wait)
|
|
166
186
|
# The wait for the lock and the spacing is not part of the answer time.
|
|
167
187
|
started = time.monotonic()
|
|
168
188
|
try:
|
|
@@ -174,6 +194,14 @@ class WebControlPro:
|
|
|
174
194
|
self._status_last = time.monotonic()
|
|
175
195
|
return answer, self._status_last - started
|
|
176
196
|
|
|
197
|
+
def _status_wait(self) -> float:
|
|
198
|
+
"""Return the seconds until a status request may be sent."""
|
|
199
|
+
now = time.monotonic()
|
|
200
|
+
return max(
|
|
201
|
+
self.request_spacing - (now - self._status_last),
|
|
202
|
+
self.command_spacing - (now - self._command_last),
|
|
203
|
+
)
|
|
204
|
+
|
|
177
205
|
async def _action(
|
|
178
206
|
self,
|
|
179
207
|
actions: list[dict[str, Any]],
|
|
@@ -183,6 +183,7 @@ def make_control(gateway: FakeGateway) -> Callable[..., WebControlPro]:
|
|
|
183
183
|
def factory(**kwargs: Any) -> WebControlPro:
|
|
184
184
|
kwargs.setdefault("retry_delay", 0)
|
|
185
185
|
kwargs.setdefault("request_spacing", 0)
|
|
186
|
+
kwargs.setdefault("command_spacing", 0)
|
|
186
187
|
return WebControlPro("gateway", gateway, **kwargs) # type: ignore[arg-type] # fake session
|
|
187
188
|
|
|
188
189
|
return factory
|
|
@@ -131,7 +131,8 @@ async def cover(control: WebControlPro, clock: Clock) -> Cover:
|
|
|
131
131
|
for direction in TravelDirection:
|
|
132
132
|
await cover.drive.set_travel_time(direction, TRAVEL_TIME)
|
|
133
133
|
# The tests of the turn time set it themselves.
|
|
134
|
-
|
|
134
|
+
for direction in TravelDirection:
|
|
135
|
+
await cover.rotation.set_turn_time(direction, 0)
|
|
135
136
|
await cover.apply_measurement(100, 75)
|
|
136
137
|
return cover
|
|
137
138
|
|
|
@@ -474,7 +475,8 @@ async def test_measurement_is_stored_at_once(
|
|
|
474
475
|
async def test_drive_waits_for_the_turn_of_the_slats(
|
|
475
476
|
cover: Cover, clock: Clock
|
|
476
477
|
) -> None:
|
|
477
|
-
|
|
478
|
+
for direction in TravelDirection:
|
|
479
|
+
await cover.rotation.set_turn_time(direction, 1.6)
|
|
478
480
|
|
|
479
481
|
delay = await cover.move(40, rotation=0)
|
|
480
482
|
|
|
@@ -493,7 +495,8 @@ async def test_drive_waits_for_the_turn_of_the_slats(
|
|
|
493
495
|
async def test_rotation_alone_waits_for_the_turn(
|
|
494
496
|
cover: Cover, gateway: FakeGateway, clock: Clock
|
|
495
497
|
) -> None:
|
|
496
|
-
|
|
498
|
+
for direction in TravelDirection:
|
|
499
|
+
await cover.rotation.set_turn_time(direction, 1.6)
|
|
497
500
|
|
|
498
501
|
delay = await cover.set_rotation(0)
|
|
499
502
|
|
|
@@ -531,3 +534,21 @@ async def test_command_waits_for_a_running_status_request(
|
|
|
531
534
|
|
|
532
535
|
assert gateway.most_in_flight == 1
|
|
533
536
|
assert [r["command"] for r in gateway.requests[-2:]] == ["getStatus", "action"]
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
async def test_stop_soon_after_a_stop_is_not_sent_again(
|
|
540
|
+
cover: Cover, gateway: FakeGateway, clock: Clock
|
|
541
|
+
) -> None:
|
|
542
|
+
await cover.move(40)
|
|
543
|
+
clock.at(5)
|
|
544
|
+
await cover.stop()
|
|
545
|
+
clock.at(5.1)
|
|
546
|
+
|
|
547
|
+
assert await cover.stop() == pytest.approx(2)
|
|
548
|
+
|
|
549
|
+
clock.at(7)
|
|
550
|
+
await cover.stop()
|
|
551
|
+
await cover.move(60)
|
|
552
|
+
await cover.stop()
|
|
553
|
+
stops = [c for c in commands(gateway) if c[0]["actionId"] == STOP_ID]
|
|
554
|
+
assert len(stops) == 3
|
|
@@ -8,6 +8,7 @@ from typing import Any
|
|
|
8
8
|
import aiohttp
|
|
9
9
|
import pytest
|
|
10
10
|
|
|
11
|
+
from pywmswebcontrolpro.const import WMS_WebControl_pro_API_actionDescription
|
|
11
12
|
from pywmswebcontrolpro.destination import Destination
|
|
12
13
|
from pywmswebcontrolpro.exceptions import WebControlProConnectionError
|
|
13
14
|
from pywmswebcontrolpro.refresh import (
|
|
@@ -262,27 +263,68 @@ def test_stats_stale_changes(
|
|
|
262
263
|
assert reported == changes
|
|
263
264
|
|
|
264
265
|
|
|
266
|
+
class FakeTime:
|
|
267
|
+
"""Clock of the client that only the fake sleep moves on."""
|
|
268
|
+
|
|
269
|
+
def __init__(self) -> None:
|
|
270
|
+
self.now = 1000.0
|
|
271
|
+
self.sleeps: list[float] = []
|
|
272
|
+
|
|
273
|
+
def monotonic(self) -> float:
|
|
274
|
+
return self.now
|
|
275
|
+
|
|
276
|
+
async def sleep(self, delay: float) -> None:
|
|
277
|
+
self.sleeps.append(delay)
|
|
278
|
+
self.now += delay
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@pytest.fixture
|
|
282
|
+
def fake_time(monkeypatch: pytest.MonkeyPatch) -> FakeTime:
|
|
283
|
+
"""Replace the clock and the sleep of the client."""
|
|
284
|
+
fake = FakeTime()
|
|
285
|
+
monkeypatch.setattr("pywmswebcontrolpro.webcontrol.time", fake)
|
|
286
|
+
monkeypatch.setattr("pywmswebcontrolpro.webcontrol.asyncio.sleep", fake.sleep)
|
|
287
|
+
return fake
|
|
288
|
+
|
|
289
|
+
|
|
265
290
|
async def test_request_spacing_delays_the_next_status_request(
|
|
266
291
|
make_control: Callable[..., WebControlPro],
|
|
267
292
|
gateway: FakeGateway,
|
|
268
|
-
|
|
293
|
+
fake_time: FakeTime,
|
|
269
294
|
) -> None:
|
|
270
295
|
"""Two status requests are at least request_spacing seconds apart."""
|
|
271
296
|
control = make_control(request_spacing=0.25)
|
|
272
297
|
await control.refresh()
|
|
273
|
-
sleeps: list[float] = []
|
|
274
|
-
|
|
275
|
-
async def fake_sleep(delay: float) -> None:
|
|
276
|
-
sleeps.append(delay)
|
|
277
|
-
|
|
278
|
-
monkeypatch.setattr("pywmswebcontrolpro.webcontrol.asyncio.sleep", fake_sleep)
|
|
279
298
|
gateway.status_answers = [status_ok(), status_ok()]
|
|
280
299
|
|
|
281
300
|
await control.dests[7].refresh(retries=0)
|
|
282
301
|
await control.dests[7].refresh(retries=0)
|
|
283
302
|
|
|
284
|
-
assert
|
|
285
|
-
|
|
303
|
+
assert fake_time.sleeps == [0.25]
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
async def test_status_request_waits_after_a_command(
|
|
307
|
+
make_control: Callable[..., WebControlPro],
|
|
308
|
+
gateway: FakeGateway,
|
|
309
|
+
fake_time: FakeTime,
|
|
310
|
+
) -> None:
|
|
311
|
+
"""A status request right after a command waits command_spacing seconds.
|
|
312
|
+
|
|
313
|
+
The hub sends an accepted command on the radio afterwards and answers a
|
|
314
|
+
status request in that time with radio busy.
|
|
315
|
+
"""
|
|
316
|
+
control = make_control(command_spacing=2.0)
|
|
317
|
+
await control.refresh()
|
|
318
|
+
gateway.status_answers = [status_ok()]
|
|
319
|
+
await control.dests[7].action(
|
|
320
|
+
WMS_WebControl_pro_API_actionDescription.RollerShutterBlindDrive
|
|
321
|
+
)(percentage=50)
|
|
322
|
+
fake_time.now += 0.5
|
|
323
|
+
|
|
324
|
+
await control.dests[7].refresh(retries=0)
|
|
325
|
+
|
|
326
|
+
assert fake_time.sleeps == [1.5]
|
|
327
|
+
assert [r["command"] for r in gateway.requests[-2:]] == ["action", "getStatus"]
|
|
286
328
|
|
|
287
329
|
|
|
288
330
|
@pytest.mark.parametrize(
|
|
@@ -482,7 +482,8 @@ async def test_diag_contains_settings_and_model(
|
|
|
482
482
|
assert diag["settings"] == {
|
|
483
483
|
"travel_time_open": 30.0,
|
|
484
484
|
"travel_time_close": 0.0,
|
|
485
|
-
"
|
|
485
|
+
"turn_time_open": 1.6,
|
|
486
|
+
"turn_time_close": 1.6,
|
|
486
487
|
}
|
|
487
488
|
assert diag["model"]["percentage"] == 60
|
|
488
489
|
assert diag["model"]["source"] == "measured"
|
|
@@ -578,18 +579,20 @@ async def test_change_during_a_write_is_stored_with_the_next_write(
|
|
|
578
579
|
assert stored["travel_time_open"] == 20.0
|
|
579
580
|
|
|
580
581
|
|
|
581
|
-
async def
|
|
582
|
+
async def test_turn_times_survive_restart(
|
|
582
583
|
make_control: ControlFactory, tmp_path: Path
|
|
583
584
|
) -> None:
|
|
584
|
-
"""
|
|
585
|
+
"""Both turn times start at 1.6 s, only a changed one is stored."""
|
|
585
586
|
action = await new_action(make_control, tmp_path)
|
|
586
|
-
assert action.settings.turn_time == 1.6
|
|
587
|
+
assert action.settings.turn_time(TravelDirection.OPEN) == 1.6
|
|
588
|
+
assert action.settings.turn_time(TravelDirection.CLOSE) == 1.6
|
|
587
589
|
|
|
588
|
-
await action.set_turn_time(2.3)
|
|
590
|
+
await action.set_turn_time(TravelDirection.CLOSE, 2.3)
|
|
589
591
|
restarted = await new_action(make_control, tmp_path)
|
|
590
592
|
|
|
591
|
-
assert restarted.settings.turn_time ==
|
|
592
|
-
assert
|
|
593
|
+
assert restarted.settings.turn_time(TravelDirection.OPEN) == 1.6
|
|
594
|
+
assert restarted.settings.turn_time(TravelDirection.CLOSE) == 2.3
|
|
595
|
+
assert stored_settings(tmp_path) == {ACTION: {"settings": {"turn_time_close": 2.3}}}
|
|
593
596
|
|
|
594
597
|
|
|
595
598
|
@pytest.mark.parametrize("seconds", [-0.1, float("nan"), float("inf")])
|
|
@@ -600,7 +603,7 @@ async def test_invalid_turn_time_is_rejected(
|
|
|
600
603
|
action = await new_action(make_control, tmp_path)
|
|
601
604
|
|
|
602
605
|
with pytest.raises(ValueError, match="must be a number"):
|
|
603
|
-
await action.set_turn_time(seconds)
|
|
606
|
+
await action.set_turn_time(TravelDirection.OPEN, seconds)
|
|
604
607
|
|
|
605
608
|
assert is_empty(tmp_path)
|
|
606
609
|
|
|
@@ -610,8 +613,13 @@ async def test_invalid_stored_turn_time_is_the_default(
|
|
|
610
613
|
make_control: ControlFactory, tmp_path: Path, stored: object
|
|
611
614
|
) -> None:
|
|
612
615
|
"""A turn time that is no number of seconds falls back to 1.6 s."""
|
|
613
|
-
write_file(
|
|
616
|
+
write_file(
|
|
617
|
+
tmp_path,
|
|
618
|
+
SETTINGS_FILE,
|
|
619
|
+
{"settings": {"turn_time_open": stored, "turn_time_close": stored}},
|
|
620
|
+
)
|
|
614
621
|
|
|
615
622
|
action = await new_action(make_control, tmp_path)
|
|
616
623
|
|
|
617
|
-
assert action.settings.turn_time == 1.6
|
|
624
|
+
assert action.settings.turn_time(TravelDirection.OPEN) == 1.6
|
|
625
|
+
assert action.settings.turn_time(TravelDirection.CLOSE) == 1.6
|
|
@@ -403,7 +403,9 @@ def test_t27_windows_are_settings() -> None:
|
|
|
403
403
|
def test_t28_slats_turn_before_and_after_the_drive() -> None:
|
|
404
404
|
model = known(0, -75)
|
|
405
405
|
|
|
406
|
-
delay = model.start_move(
|
|
406
|
+
delay = model.start_move(
|
|
407
|
+
0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.5, 1.5)
|
|
408
|
+
)
|
|
407
409
|
|
|
408
410
|
assert delay == pytest.approx(1.5 + 16 + 0.75 + 2)
|
|
409
411
|
assert model.is_closing
|
|
@@ -421,7 +423,7 @@ def test_t28_slats_turn_before_and_after_the_drive() -> None:
|
|
|
421
423
|
|
|
422
424
|
def test_t29_stop_while_the_slats_turn_keeps_their_rotation() -> None:
|
|
423
425
|
model = known(0, -75)
|
|
424
|
-
model.start_move(0.0, 40, 40, 40, 0, rotation_range=SLATS,
|
|
426
|
+
model.start_move(0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.5, 1.5))
|
|
425
427
|
|
|
426
428
|
model.stop(0.75)
|
|
427
429
|
model.advance(100.0)
|
|
@@ -432,7 +434,7 @@ def test_t29_stop_while_the_slats_turn_keeps_their_rotation() -> None:
|
|
|
432
434
|
def test_t30_rotation_alone_turns_over_time() -> None:
|
|
433
435
|
model = known(40, -75)
|
|
434
436
|
|
|
435
|
-
delay = model.set_rotation(0.0, 75, rotation_range=SLATS,
|
|
437
|
+
delay = model.set_rotation(0.0, 75, rotation_range=SLATS, turn_times=(1.5, 1.5))
|
|
436
438
|
|
|
437
439
|
assert delay == pytest.approx(1.5 + 2)
|
|
438
440
|
assert model.is_travelling
|
|
@@ -471,7 +473,9 @@ def test_t31_turn_duration_follows_the_angle(
|
|
|
471
473
|
def test_t32_turn_from_an_unknown_rotation_takes_the_full_turn_time() -> None:
|
|
472
474
|
model = known(0, None)
|
|
473
475
|
|
|
474
|
-
delay = model.start_move(
|
|
476
|
+
delay = model.start_move(
|
|
477
|
+
0.0, 40, 40, 40, rotation_range=SLATS, turn_times=(1.5, 1.5)
|
|
478
|
+
)
|
|
475
479
|
|
|
476
480
|
assert delay == pytest.approx(1.5 + 16 + 2)
|
|
477
481
|
assert model.rotation == 75
|
|
@@ -481,8 +485,31 @@ def test_t32_turn_from_an_unknown_rotation_takes_the_full_turn_time() -> None:
|
|
|
481
485
|
def test_t33_same_target_with_rotation_turns_and_counts_as_drive() -> None:
|
|
482
486
|
model = known(40, 75)
|
|
483
487
|
|
|
484
|
-
delay = model.start_move(
|
|
488
|
+
delay = model.start_move(
|
|
489
|
+
0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.5, 1.5)
|
|
490
|
+
)
|
|
485
491
|
|
|
486
492
|
assert delay == pytest.approx(0.75 + 2)
|
|
487
493
|
assert model.drive_running(0.75 + 1.9) is True
|
|
488
494
|
assert model.drive_running(0.75 + 2.1) is False
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def test_t34_each_direction_of_the_turn_has_its_own_time() -> None:
|
|
498
|
+
model = known(0, -75)
|
|
499
|
+
|
|
500
|
+
delay = model.start_move(
|
|
501
|
+
0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.0, 2.0)
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
# Turn to the maximum with the closing time, back to 0 with the opening time.
|
|
505
|
+
assert delay == pytest.approx(2.0 + 16 + 0.5 + 2)
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def test_t35_turn_from_an_unknown_rotation_takes_the_longer_time() -> None:
|
|
509
|
+
model = known(0, None)
|
|
510
|
+
|
|
511
|
+
delay = model.start_move(
|
|
512
|
+
0.0, 40, 40, 40, rotation_range=SLATS, turn_times=(1.0, 2.0)
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
assert delay == pytest.approx(2.0 + 16 + 2)
|
|
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
|