pywmswebcontrolpro 0.9.2__tar.gz → 0.10.1__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.1}/CHANGELOG.md +27 -1
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/PKG-INFO +12 -10
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/README.md +11 -9
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/action.py +9 -6
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/cover.py +17 -2
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/store.py +11 -3
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/travel.py +64 -30
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/webcontrol.py +33 -5
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/conftest.py +1 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_cover.py +29 -8
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_refresh.py +51 -9
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_settings.py +18 -10
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_travel.py +46 -14
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/.gitignore +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/.python-version +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/LICENSE +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/destination.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.9.2 → pywmswebcontrolpro-0.10.1}/tests/test_rotation.py +0 -0
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.10.1 (unreleased)
|
|
4
|
+
|
|
5
|
+
Fixed:
|
|
6
|
+
|
|
7
|
+
- The slats of a slat drive turn to the rotation of the direction while the cover
|
|
8
|
+
drives, not before it: one motor drives the cover and turns the slats, and the
|
|
9
|
+
travel times include the turn. Only the turn to the rotation sent with a drive
|
|
10
|
+
follows after the target. A drive ends and is polled that much earlier.
|
|
11
|
+
|
|
12
|
+
## 0.10.0
|
|
13
|
+
|
|
14
|
+
Changed:
|
|
15
|
+
|
|
16
|
+
- The slats have a turn time for each direction, like in the device settings of the
|
|
17
|
+
hub: `Action.set_turn_time(direction, seconds)` with `TravelDirection.OPEN` for a
|
|
18
|
+
turn to the minimum rotation and `TravelDirection.CLOSE` for a turn to the maximum.
|
|
19
|
+
Both are 1.6 seconds by default. `ActionSettings.turn_time(direction)` returns one,
|
|
20
|
+
`CoverModel.start_move` and `CoverModel.set_rotation` take `turn_times` (open,
|
|
21
|
+
close). A turn from an unknown rotation takes the longer full turn time.
|
|
22
|
+
- A status request waits until 2 seconds after the last command to the hub
|
|
23
|
+
(`command_spacing`, `DEFAULT_COMMAND_SPACING`). The hub accepts a command at once and
|
|
24
|
+
sends it on the radio afterwards; a status request right after it was answered with
|
|
25
|
+
radio busy in live tests.
|
|
26
|
+
- A stop within 1 second after a stop of the same cover, with no other command
|
|
27
|
+
between, is not sent again (`TravelSettings.stop_repeat_window`).
|
|
28
|
+
|
|
29
|
+
## 0.9.2
|
|
4
30
|
|
|
5
31
|
Changed:
|
|
6
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pywmswebcontrolpro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.1
|
|
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.
|
|
@@ -206,14 +206,16 @@ The windows are `TravelSettings.combine_window` and
|
|
|
206
206
|
`TravelSettings.combine_window_untimed`. A drive that the library did not send, for
|
|
207
207
|
example from a wall switch, is not known and not taken along.
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
the slats in the same way.
|
|
214
|
-
|
|
215
|
-
rotation, `
|
|
216
|
-
|
|
209
|
+
One motor drives a slat drive and turns its slats. As a drive starts, the slats turn to
|
|
210
|
+
the minimum rotation when the cover drives up and to the maximum when it drives down,
|
|
211
|
+
while the cover drives; the travel times include this turn. After the target the hub
|
|
212
|
+
turns the slats to the rotation sent with the drive; without one they stay at the
|
|
213
|
+
rotation of the direction. A rotation alone turns 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.
|
|
@@ -192,14 +192,16 @@ The windows are `TravelSettings.combine_window` and
|
|
|
192
192
|
`TravelSettings.combine_window_untimed`. A drive that the library did not send, for
|
|
193
193
|
example from a wall switch, is not known and not taken along.
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
the slats in the same way.
|
|
200
|
-
|
|
201
|
-
rotation, `
|
|
202
|
-
|
|
195
|
+
One motor drives a slat drive and turns its slats. As a drive starts, the slats turn to
|
|
196
|
+
the minimum rotation when the cover drives up and to the maximum when it drives down,
|
|
197
|
+
while the cover drives; the travel times include this turn. After the target the hub
|
|
198
|
+
turns the slats to the rotation sent with the drive; without one they stay at the
|
|
199
|
+
rotation of the direction. A rotation alone turns 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)
|
|
@@ -104,10 +107,11 @@ def closed_rotations(minimum: float, maximum: float) -> list[int]:
|
|
|
104
107
|
|
|
105
108
|
@dataclass(frozen=True)
|
|
106
109
|
class _Motion:
|
|
107
|
-
"""A movement of the cover in
|
|
110
|
+
"""A movement of the cover in two phases, each may take no time.
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
One motor drives the cover and turns the slats: when the drive starts,
|
|
113
|
+
the slats turn to the rotation of its direction while the cover drives.
|
|
114
|
+
After the target, the slats turn to the rotation for the end.
|
|
111
115
|
"""
|
|
112
116
|
|
|
113
117
|
started_at: float
|
|
@@ -120,9 +124,13 @@ class _Motion:
|
|
|
120
124
|
drive: float
|
|
121
125
|
last_turn: float
|
|
122
126
|
|
|
127
|
+
@property
|
|
128
|
+
def drive_phase(self) -> float:
|
|
129
|
+
return max(self.first_turn, self.drive)
|
|
130
|
+
|
|
123
131
|
@property
|
|
124
132
|
def duration(self) -> float:
|
|
125
|
-
return self.
|
|
133
|
+
return self.drive_phase + self.last_turn
|
|
126
134
|
|
|
127
135
|
|
|
128
136
|
def _between(start: int | None, end: int, share: float) -> int:
|
|
@@ -151,6 +159,16 @@ def turn_duration(
|
|
|
151
159
|
return turn_time * min(1.0, abs(end - start) / span)
|
|
152
160
|
|
|
153
161
|
|
|
162
|
+
def _turn_time(start: int | None, end: int, turn_times: tuple[float, float]) -> float:
|
|
163
|
+
"""Return the turn time of the direction, the longer one from an unknown start.
|
|
164
|
+
|
|
165
|
+
turn_times are the times to the minimum and to the maximum rotation.
|
|
166
|
+
"""
|
|
167
|
+
if start is None:
|
|
168
|
+
return max(turn_times)
|
|
169
|
+
return turn_times[0] if end < start else turn_times[1]
|
|
170
|
+
|
|
171
|
+
|
|
154
172
|
class CoverModel:
|
|
155
173
|
"""Displayed state of one cover in the units of the hub."""
|
|
156
174
|
|
|
@@ -262,25 +280,29 @@ class CoverModel:
|
|
|
262
280
|
if motion is None:
|
|
263
281
|
return False
|
|
264
282
|
elapsed = max(0.0, now - motion.started_at)
|
|
265
|
-
if elapsed < motion.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
283
|
+
if elapsed < motion.drive_phase:
|
|
284
|
+
if motion.drive > 0:
|
|
285
|
+
self.percentage = motion.start + (motion.target - motion.start) * min(
|
|
286
|
+
1.0, elapsed / motion.drive
|
|
287
|
+
)
|
|
288
|
+
if motion.drive_rotation is not None:
|
|
289
|
+
self.rotation = (
|
|
290
|
+
_between(
|
|
291
|
+
motion.turn_from,
|
|
292
|
+
motion.drive_rotation,
|
|
293
|
+
min(1.0, elapsed / motion.first_turn),
|
|
294
|
+
)
|
|
295
|
+
if motion.first_turn > 0
|
|
296
|
+
else motion.drive_rotation
|
|
297
|
+
)
|
|
270
298
|
return False
|
|
271
299
|
# A turn without a drive starts where the slats were.
|
|
272
300
|
turn_start = (
|
|
273
301
|
motion.turn_from if motion.drive_rotation is None else motion.drive_rotation
|
|
274
302
|
)
|
|
275
|
-
elapsed -= motion.
|
|
303
|
+
elapsed -= motion.drive_phase
|
|
276
304
|
if motion.drive_rotation is not None:
|
|
277
305
|
self.rotation = motion.drive_rotation
|
|
278
|
-
if elapsed < motion.drive:
|
|
279
|
-
self.percentage = motion.start + (motion.target - motion.start) * (
|
|
280
|
-
elapsed / motion.drive
|
|
281
|
-
)
|
|
282
|
-
return False
|
|
283
|
-
elapsed -= motion.drive
|
|
284
306
|
self.percentage = motion.target
|
|
285
307
|
if elapsed < motion.last_turn and motion.end_rotation is not None:
|
|
286
308
|
self.rotation = _between(
|
|
@@ -303,16 +325,17 @@ class CoverModel:
|
|
|
303
325
|
rotation: int | None = None,
|
|
304
326
|
*,
|
|
305
327
|
rotation_range: tuple[float, float] | None = None,
|
|
306
|
-
|
|
328
|
+
turn_times: tuple[float, float] = (0.0, 0.0),
|
|
307
329
|
) -> float:
|
|
308
330
|
"""Handle an accepted drive command to a percentage.
|
|
309
331
|
|
|
310
332
|
rotation is the rotation sent for the end of the drive. With the
|
|
311
|
-
rotation range of slats, the slats
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
the
|
|
333
|
+
rotation range of slats, the slats turn to the limit of the direction,
|
|
334
|
+
the minimum up and the maximum down, as the drive starts, since the
|
|
335
|
+
same motor turns them; the travel times include this turn. After the
|
|
336
|
+
target the slats turn to the rotation for the end; without one they
|
|
337
|
+
stay at the limit. turn_times are the times of the slats over the whole
|
|
338
|
+
rotation range, to the minimum and to the maximum rotation.
|
|
316
339
|
|
|
317
340
|
Returns the delay in seconds until the settle poll.
|
|
318
341
|
"""
|
|
@@ -336,7 +359,7 @@ class CoverModel:
|
|
|
336
359
|
self.percentage = target
|
|
337
360
|
if rotation is None:
|
|
338
361
|
return self.settings.settle_rotation
|
|
339
|
-
return self._turn(now, rotation, rotation_range,
|
|
362
|
+
return self._turn(now, rotation, rotation_range, turn_times)
|
|
340
363
|
|
|
341
364
|
opening = target < start
|
|
342
365
|
drive_rotation: int | None = None
|
|
@@ -345,11 +368,17 @@ class CoverModel:
|
|
|
345
368
|
limit = rotation_range[0] if opening else rotation_range[1]
|
|
346
369
|
drive_rotation = math.floor(limit + 0.5)
|
|
347
370
|
first_turn = turn_duration(
|
|
348
|
-
self.rotation,
|
|
371
|
+
self.rotation,
|
|
372
|
+
drive_rotation,
|
|
373
|
+
rotation_range,
|
|
374
|
+
_turn_time(self.rotation, drive_rotation, turn_times),
|
|
349
375
|
)
|
|
350
376
|
if rotation is not None:
|
|
351
377
|
last_turn = turn_duration(
|
|
352
|
-
drive_rotation,
|
|
378
|
+
drive_rotation,
|
|
379
|
+
rotation,
|
|
380
|
+
rotation_range,
|
|
381
|
+
_turn_time(drive_rotation, rotation, turn_times),
|
|
353
382
|
)
|
|
354
383
|
full_time = time_open if opening else time_close
|
|
355
384
|
if full_time <= 0:
|
|
@@ -382,29 +411,34 @@ class CoverModel:
|
|
|
382
411
|
rotation: int,
|
|
383
412
|
*,
|
|
384
413
|
rotation_range: tuple[float, float] | None = None,
|
|
385
|
-
|
|
414
|
+
turn_times: tuple[float, float] = (0.0, 0.0),
|
|
386
415
|
) -> float:
|
|
387
416
|
"""Handle an accepted rotation-only command, it ends a running drive.
|
|
388
417
|
|
|
389
|
-
With the rotation range and the turn
|
|
418
|
+
With the rotation range and the turn times the slats turn over time.
|
|
390
419
|
"""
|
|
391
420
|
self.advance(now)
|
|
392
421
|
self._motion = None
|
|
393
422
|
self._forget_commands()
|
|
394
423
|
self.source = PositionSource.CALCULATED
|
|
395
|
-
return self._turn(now, rotation, rotation_range,
|
|
424
|
+
return self._turn(now, rotation, rotation_range, turn_times)
|
|
396
425
|
|
|
397
426
|
def _turn(
|
|
398
427
|
self,
|
|
399
428
|
now: float,
|
|
400
429
|
rotation: int,
|
|
401
430
|
rotation_range: tuple[float, float] | None,
|
|
402
|
-
|
|
431
|
+
turn_times: tuple[float, float],
|
|
403
432
|
) -> float:
|
|
404
433
|
duration = (
|
|
405
434
|
0.0
|
|
406
435
|
if rotation_range is None or self.percentage is None
|
|
407
|
-
else turn_duration(
|
|
436
|
+
else turn_duration(
|
|
437
|
+
self.rotation,
|
|
438
|
+
rotation,
|
|
439
|
+
rotation_range,
|
|
440
|
+
_turn_time(self.rotation, rotation, turn_times),
|
|
441
|
+
)
|
|
408
442
|
)
|
|
409
443
|
if duration <= 0 or self.percentage is None:
|
|
410
444
|
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,18 +475,19 @@ 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
|
|
|
481
|
-
#
|
|
482
|
-
assert delay == pytest.approx(
|
|
483
|
+
# Drive 24 s while the slats turn up, then turn to 0 0.8 s, then the settle time.
|
|
484
|
+
assert delay == pytest.approx(24 + 0.8 + 2)
|
|
483
485
|
clock.at(0.8)
|
|
484
486
|
cover.advance()
|
|
485
|
-
assert (cover.model.percentage_int, cover.model.rotation) == (
|
|
486
|
-
clock.at(
|
|
487
|
+
assert (cover.model.percentage_int, cover.model.rotation) == (98, 0)
|
|
488
|
+
clock.at(24.4)
|
|
487
489
|
assert (await cover.apply_measurement(40, -30)).applied is False
|
|
488
|
-
clock.at(
|
|
490
|
+
clock.at(24.9)
|
|
489
491
|
assert cover.advance() is True
|
|
490
492
|
assert (cover.model.percentage_int, cover.model.rotation) == (40, 0)
|
|
491
493
|
|
|
@@ -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
|
|
@@ -400,39 +400,44 @@ def test_t27_windows_are_settings() -> None:
|
|
|
400
400
|
assert model.recent_rotation(4.9) == 45
|
|
401
401
|
|
|
402
402
|
|
|
403
|
-
def
|
|
403
|
+
def test_t28_slats_turn_as_the_drive_starts_and_after_it() -> 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
|
+
# One motor: the slats turn while the cover drives, then turn to the end.
|
|
411
|
+
assert delay == pytest.approx(16 + 0.75 + 2)
|
|
409
412
|
assert model.is_closing
|
|
410
413
|
model.advance(0.75)
|
|
411
|
-
assert
|
|
412
|
-
model.
|
|
414
|
+
assert model.rotation == 0
|
|
415
|
+
assert model.percentage == pytest.approx(1.875)
|
|
416
|
+
model.advance(8)
|
|
413
417
|
assert (model.percentage_int, model.rotation) == (20, 75)
|
|
414
|
-
assert model.advance(
|
|
418
|
+
assert model.advance(16 + 0.375) is False
|
|
415
419
|
assert (model.percentage_int, model.rotation) == (40, 38)
|
|
416
|
-
assert model.apply_measurement(
|
|
417
|
-
assert model.advance(
|
|
420
|
+
assert model.apply_measurement(16.4, 40, 75) == travel.Measurement(False, False)
|
|
421
|
+
assert model.advance(16.75) is True
|
|
418
422
|
assert model.rotation == 0
|
|
419
423
|
assert not model.is_travelling
|
|
420
424
|
|
|
421
425
|
|
|
422
426
|
def test_t29_stop_while_the_slats_turn_keeps_their_rotation() -> None:
|
|
423
427
|
model = known(0, -75)
|
|
424
|
-
model.start_move(0.0, 40, 40, 40, 0, rotation_range=SLATS,
|
|
428
|
+
model.start_move(0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.5, 1.5))
|
|
425
429
|
|
|
426
430
|
model.stop(0.75)
|
|
427
431
|
model.advance(100.0)
|
|
428
432
|
|
|
429
|
-
assert
|
|
433
|
+
assert model.rotation == 0
|
|
434
|
+
assert model.percentage == pytest.approx(1.875)
|
|
430
435
|
|
|
431
436
|
|
|
432
437
|
def test_t30_rotation_alone_turns_over_time() -> None:
|
|
433
438
|
model = known(40, -75)
|
|
434
439
|
|
|
435
|
-
delay = model.set_rotation(0.0, 75, rotation_range=SLATS,
|
|
440
|
+
delay = model.set_rotation(0.0, 75, rotation_range=SLATS, turn_times=(1.5, 1.5))
|
|
436
441
|
|
|
437
442
|
assert delay == pytest.approx(1.5 + 2)
|
|
438
443
|
assert model.is_travelling
|
|
@@ -471,9 +476,12 @@ def test_t31_turn_duration_follows_the_angle(
|
|
|
471
476
|
def test_t32_turn_from_an_unknown_rotation_takes_the_full_turn_time() -> None:
|
|
472
477
|
model = known(0, None)
|
|
473
478
|
|
|
474
|
-
delay = model.start_move(
|
|
479
|
+
delay = model.start_move(
|
|
480
|
+
0.0, 2, 40, 40, rotation_range=SLATS, turn_times=(1.5, 1.5)
|
|
481
|
+
)
|
|
475
482
|
|
|
476
|
-
|
|
483
|
+
# The drive takes 0.8 s, the full turn longer.
|
|
484
|
+
assert delay == pytest.approx(1.5 + 2)
|
|
477
485
|
assert model.rotation == 75
|
|
478
486
|
assert model.snapshot()["target_rotation"] == 75
|
|
479
487
|
|
|
@@ -481,8 +489,32 @@ def test_t32_turn_from_an_unknown_rotation_takes_the_full_turn_time() -> None:
|
|
|
481
489
|
def test_t33_same_target_with_rotation_turns_and_counts_as_drive() -> None:
|
|
482
490
|
model = known(40, 75)
|
|
483
491
|
|
|
484
|
-
delay = model.start_move(
|
|
492
|
+
delay = model.start_move(
|
|
493
|
+
0.0, 40, 40, 40, 0, rotation_range=SLATS, turn_times=(1.5, 1.5)
|
|
494
|
+
)
|
|
485
495
|
|
|
486
496
|
assert delay == pytest.approx(0.75 + 2)
|
|
487
497
|
assert model.drive_running(0.75 + 1.9) is True
|
|
488
498
|
assert model.drive_running(0.75 + 2.1) is False
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def test_t34_each_direction_of_the_turn_has_its_own_time() -> None:
|
|
502
|
+
model = known(0, -75)
|
|
503
|
+
|
|
504
|
+
delay = model.start_move(
|
|
505
|
+
0.0, 2, 40, 40, 0, rotation_range=SLATS, turn_times=(1.0, 2.0)
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
# A short drive waits for the turn to the maximum with the closing time,
|
|
509
|
+
# then the slats turn back to 0 with the opening time.
|
|
510
|
+
assert delay == pytest.approx(2.0 + 0.5 + 2)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def test_t35_turn_from_an_unknown_rotation_takes_the_longer_time() -> None:
|
|
514
|
+
model = known(0, None)
|
|
515
|
+
|
|
516
|
+
delay = model.start_move(
|
|
517
|
+
0.0, 2, 40, 40, rotation_range=SLATS, turn_times=(1.0, 2.0)
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
assert delay == pytest.approx(2.0 + 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
|