pywmswebcontrolpro 0.6.0__tar.gz → 0.8.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 (40) hide show
  1. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/CHANGELOG.md +56 -0
  2. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/PKG-INFO +67 -32
  3. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/README.md +66 -31
  4. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/action.py +29 -42
  5. pywmswebcontrolpro-0.8.0/pywmswebcontrolpro/cover.py +183 -0
  6. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/destination.py +26 -0
  7. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/store.py +0 -7
  8. pywmswebcontrolpro-0.8.0/pywmswebcontrolpro/travel.py +383 -0
  9. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/conftest.py +8 -2
  10. pywmswebcontrolpro-0.8.0/tests/test_cover.py +469 -0
  11. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_rotation.py +34 -112
  12. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_settings.py +26 -25
  13. pywmswebcontrolpro-0.8.0/tests/test_travel.py +400 -0
  14. pywmswebcontrolpro-0.6.0/pywmswebcontrolpro/travel.py +0 -338
  15. pywmswebcontrolpro-0.6.0/tests/test_travel.py +0 -225
  16. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/.github/workflows/release.yaml +0 -0
  17. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/.github/workflows/validate.yaml +0 -0
  18. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/.gitignore +0 -0
  19. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/.python-version +0 -0
  20. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/LICENSE +0 -0
  21. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/mypy.ini +0 -0
  22. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pyproject.toml +0 -0
  23. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pytest.ini +0 -0
  24. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/__init__.py +0 -0
  25. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/const.py +0 -0
  26. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/exceptions.py +0 -0
  27. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/py.typed +0 -0
  28. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/refresh.py +0 -0
  29. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/room.py +0 -0
  30. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/scene.py +0 -0
  31. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/pywmswebcontrolpro/webcontrol.py +0 -0
  32. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/requirements_lint.txt +0 -0
  33. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/requirements_test.txt +0 -0
  34. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/ruff.toml +0 -0
  35. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/simulator/simulator.py +0 -0
  36. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/__init__.py +0 -0
  37. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_client.py +0 -0
  38. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_configuration.py +0 -0
  39. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_import.py +0 -0
  40. {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.8.0}/tests/test_refresh.py +0 -0
@@ -1,5 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0 (unreleased)
4
+
5
+ Breaking changes:
6
+
7
+ - `Cover.apply_measurement` is a coroutine. It stores a changed state at once, until
8
+ now a measured value reached `state.json` only with the next status request or
9
+ command.
10
+
11
+ ## 0.7.0
12
+
13
+ Breaking changes:
14
+
15
+ - The library uses the values of the hub only: the percentage of a drive (0 open, 100
16
+ closed) and the rotation of slats in degrees. The position and tilt of Home
17
+ Assistant (0 to 100) are converted by the application.
18
+ - `CoverModel` keeps `percentage` and `rotation` instead of `position` and `tilt`,
19
+ `percentage_int` replaces `position_int`, `set_rotation` replaces `set_tilt`.
20
+ `start_move` takes the rotation for the end of the drive and the `rotation_range` of
21
+ slats instead of `tilt`, `rotation` and `slats`. `Action.start_move` and
22
+ `apply_measurement` take a percentage and a rotation.
23
+ - `TravelSettings.settle_tilt` is now `settle_rotation`, `position_tolerance` is now
24
+ `percentage_tolerance`.
25
+ - Removed: `wms_percentage_to_position`, `rotation_to_tilt`, `tilt_to_rotation`,
26
+ `open_tilt`, `closed_tilts`, `rotation_to_angle` and `tilt_angles` in `travel.py`,
27
+ and `Action.rotation_to_tilt`, `Action.tilt_to_rotation`, `Action.open_tilt`,
28
+ `Action.closed_tilts` and `Action.tilt_angles`. `valid_percent` in `store.py` is now
29
+ `valid_percentage` in `travel.py`.
30
+ - `state.json` stores `percentage`, `rotation`, `target_percentage` and
31
+ `target_rotation`. The state stored by 0.6.0 is not read, the next status request
32
+ measures it again. Settings and rotation limits stay.
33
+
34
+ Added:
35
+
36
+ - `Destination.cover()` returns a `Cover` with the commands of a drive and its rotation:
37
+ `move`, `open`, `close`, `set_rotation`, `open_slats`, `close_slats` and `stop`, plus
38
+ `advance` and `apply_measurement` with the same clock. They send the command, update
39
+ and store the movement model and return the delay until the status should be
40
+ checked, see the README.
41
+ - A rotation during a running drive is sent together with the drive to its target, and a
42
+ drive within 2 seconds after a rotation repeats it. The hub runs only the last command
43
+ of a destination, so until now the rotation stopped the drive.
44
+ - Commands of one destination are sent one after the other.
45
+ - `Action.closed_rotations` and `closed_rotations` in `travel.py`, the rotations of
46
+ closed slats with the limits in use, and `valid_rotation`.
47
+ - `CoverModel.drive_running`, `CoverModel.drive_target`, `CoverModel.pending_rotation`,
48
+ `CoverModel.remember_rotation`, `CoverModel.recent_rotation` and the settings
49
+ `TravelSettings.combine_window` (2 seconds) and
50
+ `TravelSettings.combine_window_untimed` (0.5 seconds).
51
+
52
+ Changed:
53
+
54
+ - With the `rotation_range` of slats (set by `Cover` for slat drives)
55
+ `CoverModel.start_move` shows the rotation of the direction while the drive runs, the
56
+ minimum up and the maximum down, and keeps it after a drive without a rotation and
57
+ after a stop.
58
+
3
59
  ## 0.6.0
4
60
 
5
61
  Added:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pywmswebcontrolpro
3
- Version: 0.6.0
3
+ Version: 0.8.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
@@ -100,8 +100,8 @@ has a directory of its own, named by its id, with two files:
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
102
  of the rotation limits.
103
- - `state.json`: the last known position and tilt of a drive action and the target of a
104
- running drive.
103
+ - `state.json`: the last known percentage and rotation of a drive action and the
104
+ target of a running drive.
105
105
 
106
106
  Both files have an entry for each action of the destination, and only for data that
107
107
  differs from the defaults:
@@ -122,17 +122,22 @@ destination. Files of destinations that the hub does not report are not touched.
122
122
  Without a persist path nothing is stored.
123
123
 
124
124
  `Action.model` is the movement model of the cover driven by this action: `start_move`,
125
- `stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
126
- replaced by a measured value when the cover stands still. Because the model belongs to
127
- the drive action, an awning and its valance, which share a destination, move
128
- independently. After a restart the position is restored from the file and marked as
129
- `restored` until a measurement arrives. Call `Action.sync()` after commands and
125
+ `stop`, `set_rotation` and `apply_measurement` calculate the displayed percentage and
126
+ rotation, which are replaced by measured values when the cover stands still. Because
127
+ the model belongs to the drive action, an awning and its valance, which share a
128
+ destination, move independently. After a restart the state is restored from the file
129
+ and marked as `restored` until a measurement arrives.
130
+
131
+ The library uses the values of the hub only: the percentage of a drive is 0 open and
132
+ 100 closed, the rotation of slats is in whole degrees, 0 is horizontal. Scales of a
133
+ user interface, for example the position and tilt of Home Assistant, are converted by
134
+ the application. Call `Action.sync()` after commands and
130
135
  measurements to store changes; `Destination.refresh` does it as well.
131
136
 
132
137
  ## Rotation limits of slat drives (firmware bug)
133
138
 
134
139
  The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
135
- from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
140
+ from -75 to 75, so a scale calculated from the reported limits is wrong: closed slats
136
141
  (rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
137
142
  not been announced.
138
143
 
@@ -144,36 +149,66 @@ The library works around it in `pywmswebcontrolpro/action.py`:
144
149
  themselves (-127 and 127) are never learned.
145
150
  - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
146
151
  returns to the default. Both are stored in `settings.json`.
147
- - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
148
- use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
149
- rotation that is sent is a whole number within the limits.
150
152
 
151
153
  The workaround ends by itself when a firmware reports other limits. It can be removed
152
154
  from the library once such a firmware is available.
153
155
 
154
- ## Tilt model of slat drives
156
+ ## Open and closed slats
155
157
 
156
- Since Home Assistant 2026.12 a cover can describe its tilt with an open tilt position,
157
- closed tilt positions and the slat angles at tilt 0 and tilt 100. A rotation action
158
- provides these values with the limits in use, so they follow the workaround, learned
159
- and overwritten limits:
158
+ A rotation action provides the rotations of open and closed slats with the limits in
159
+ use, so they follow the workaround, learned and overwritten limits:
160
160
 
161
161
  - `Action.open_rotation` is the rotation of open slats: 0 (horizontal) if it lies within
162
- the limits, else the limit closest to 0. `Action.open_tilt` is its tilt, 50 with the
163
- limits -75 and 75.
164
- - `Action.closed_tilts` are the tilts of closed slats: the end where the slats lie the
165
- flattest, the largest absolute rotation. Slats that turn evenly over the horizontal
166
- position close at both ends, a slat roof with uneven limits at one: `[0, 100]` with
167
- -75 and 75, `[0]` with -60 and 80, `[100]` with -100 and 50. An end
168
- where the open tilt lies is left out. The first entry is the one to close to: tilt 0,
169
- the maximum rotation, which the hub also turns the slats to when it closes the cover.
170
- - `Action.tilt_angles` are the slat angles in whole degrees at tilt 0 and at tilt 100,
171
- from -90 to 90, with the sign of the rotation of the hub: `(75, -75)` with the limits
172
- -75 and 75. The rotation of the hub is in degrees, 0 is horizontal. `None` if the
173
- limits do not give two different angles.
174
-
175
- The functions behind them are in `pywmswebcontrolpro/travel.py` and take the limits as
176
- arguments.
162
+ the limits, else the limit closest to 0.
163
+ - `Action.closed_rotations` are the rotations of closed slats: the end where the slats
164
+ lie the flattest, the largest absolute rotation. Slats that turn evenly over the
165
+ horizontal position close at both ends, a slat roof with uneven limits at one:
166
+ `[75, -75]` with -75 and 75, `[80]` with -60 and 80, `[-100]` with -100 and 50. An end
167
+ where the open rotation lies is left out. The first entry is the one to close to: the
168
+ maximum, which the hub also turns the slats to when it closes the cover.
169
+
170
+ The functions behind them, `open_rotation` and `closed_rotations` in
171
+ `pywmswebcontrolpro/travel.py`, take the limits as arguments.
172
+
173
+ ## Cover commands: drive and rotation together
174
+
175
+ The hub runs only the last command of a destination: a new command aborts a drive or a
176
+ rotation that is still running. A rotation sent while a blind drives would stop the
177
+ blind where it is. `Destination.cover(<drive action description>)` returns a `Cover`
178
+ with commands that keep the two together:
179
+
180
+ - `move(percentage, rotation=None)`, `open()`, `close()`, `set_rotation(rotation)`,
181
+ `open_slats()`, `close_slats()` and `stop()` send the command,
182
+ update the movement model, store it and return the seconds until the status should be
183
+ requested to check the result. A command that the hub rejects raises a
184
+ `WebControlProError` and leaves the model unchanged.
185
+ `advance()` and `apply_measurement(percentage, rotation)` use the same clock as the
186
+ commands, `apply_measurement` stores a change at once. The hub takes whole numbers, so the percentage and the rotation are
187
+ rounded when they are sent.
188
+ - A rotation while a drive runs is sent together with the drive to its target, so the
189
+ blind keeps driving and turns its slats at the end. A drive counts as running during
190
+ the calculated drive, up to 2 seconds after its calculated end (travel times that are
191
+ a bit too short) and, without a calculated drive, up to 0.5 seconds after the hub
192
+ accepted it. Automations and scenes, for example the scenes of Home Assistant, send
193
+ the drive and the rotation right after each other.
194
+ - A drive within 2 seconds after a rotation sends that rotation again, with the value
195
+ that was sent. This also applies to `open()` and `close()`, which otherwise turn the
196
+ slats to the minimum and the maximum rotation like the hub does.
197
+ - A new drive while a drive with a rotation runs takes that rotation along.
198
+ - `move(percentage, rotation)` sends both in one command.
199
+ - `stop()` stops drive and rotation, the hub has one stop command for both. Nothing that
200
+ was sent before is repeated after a stop.
201
+ - Commands of one destination wait for each other, so the second of two commands that
202
+ arrive together sees the result of the first.
203
+
204
+ The windows are `TravelSettings.combine_window` and
205
+ `TravelSettings.combine_window_untimed`. A drive that the library did not send, for
206
+ example from a wall switch, is not known and not taken along.
207
+
208
+ While a slat drive moves, the model shows the rotation of the direction: the hub turns
209
+ the slats to the minimum rotation before it drives up and to the maximum before it
210
+ drives down. The rotation sent with the drive is shown when the drive ends; without one
211
+ the rotation of the direction stays. A stop leaves the rotation where it is.
177
212
 
178
213
  ## Development
179
214
 
@@ -86,8 +86,8 @@ has a directory of its own, named by its id, with two files:
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
88
  of the rotation limits.
89
- - `state.json`: the last known position and tilt of a drive action and the target of a
90
- running drive.
89
+ - `state.json`: the last known percentage and rotation of a drive action and the
90
+ target of a running drive.
91
91
 
92
92
  Both files have an entry for each action of the destination, and only for data that
93
93
  differs from the defaults:
@@ -108,17 +108,22 @@ destination. Files of destinations that the hub does not report are not touched.
108
108
  Without a persist path nothing is stored.
109
109
 
110
110
  `Action.model` is the movement model of the cover driven by this action: `start_move`,
111
- `stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
112
- replaced by a measured value when the cover stands still. Because the model belongs to
113
- the drive action, an awning and its valance, which share a destination, move
114
- independently. After a restart the position is restored from the file and marked as
115
- `restored` until a measurement arrives. Call `Action.sync()` after commands and
111
+ `stop`, `set_rotation` and `apply_measurement` calculate the displayed percentage and
112
+ rotation, which are replaced by measured values when the cover stands still. Because
113
+ the model belongs to the drive action, an awning and its valance, which share a
114
+ destination, move independently. After a restart the state is restored from the file
115
+ and marked as `restored` until a measurement arrives.
116
+
117
+ The library uses the values of the hub only: the percentage of a drive is 0 open and
118
+ 100 closed, the rotation of slats is in whole degrees, 0 is horizontal. Scales of a
119
+ user interface, for example the position and tilt of Home Assistant, are converted by
120
+ the application. Call `Action.sync()` after commands and
116
121
  measurements to store changes; `Destination.refresh` does it as well.
117
122
 
118
123
  ## Rotation limits of slat drives (firmware bug)
119
124
 
120
125
  The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
121
- from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
126
+ from -75 to 75, so a scale calculated from the reported limits is wrong: closed slats
122
127
  (rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
123
128
  not been announced.
124
129
 
@@ -130,36 +135,66 @@ The library works around it in `pywmswebcontrolpro/action.py`:
130
135
  themselves (-127 and 127) are never learned.
131
136
  - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
132
137
  returns to the default. Both are stored in `settings.json`.
133
- - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
134
- use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
135
- rotation that is sent is a whole number within the limits.
136
138
 
137
139
  The workaround ends by itself when a firmware reports other limits. It can be removed
138
140
  from the library once such a firmware is available.
139
141
 
140
- ## Tilt model of slat drives
142
+ ## Open and closed slats
141
143
 
142
- Since Home Assistant 2026.12 a cover can describe its tilt with an open tilt position,
143
- closed tilt positions and the slat angles at tilt 0 and tilt 100. A rotation action
144
- provides these values with the limits in use, so they follow the workaround, learned
145
- and overwritten limits:
144
+ A rotation action provides the rotations of open and closed slats with the limits in
145
+ use, so they follow the workaround, learned and overwritten limits:
146
146
 
147
147
  - `Action.open_rotation` is the rotation of open slats: 0 (horizontal) if it lies within
148
- the limits, else the limit closest to 0. `Action.open_tilt` is its tilt, 50 with the
149
- limits -75 and 75.
150
- - `Action.closed_tilts` are the tilts of closed slats: the end where the slats lie the
151
- flattest, the largest absolute rotation. Slats that turn evenly over the horizontal
152
- position close at both ends, a slat roof with uneven limits at one: `[0, 100]` with
153
- -75 and 75, `[0]` with -60 and 80, `[100]` with -100 and 50. An end
154
- where the open tilt lies is left out. The first entry is the one to close to: tilt 0,
155
- the maximum rotation, which the hub also turns the slats to when it closes the cover.
156
- - `Action.tilt_angles` are the slat angles in whole degrees at tilt 0 and at tilt 100,
157
- from -90 to 90, with the sign of the rotation of the hub: `(75, -75)` with the limits
158
- -75 and 75. The rotation of the hub is in degrees, 0 is horizontal. `None` if the
159
- limits do not give two different angles.
160
-
161
- The functions behind them are in `pywmswebcontrolpro/travel.py` and take the limits as
162
- arguments.
148
+ the limits, else the limit closest to 0.
149
+ - `Action.closed_rotations` are the rotations of closed slats: the end where the slats
150
+ lie the flattest, the largest absolute rotation. Slats that turn evenly over the
151
+ horizontal position close at both ends, a slat roof with uneven limits at one:
152
+ `[75, -75]` with -75 and 75, `[80]` with -60 and 80, `[-100]` with -100 and 50. An end
153
+ where the open rotation lies is left out. The first entry is the one to close to: the
154
+ maximum, which the hub also turns the slats to when it closes the cover.
155
+
156
+ The functions behind them, `open_rotation` and `closed_rotations` in
157
+ `pywmswebcontrolpro/travel.py`, take the limits as arguments.
158
+
159
+ ## Cover commands: drive and rotation together
160
+
161
+ The hub runs only the last command of a destination: a new command aborts a drive or a
162
+ rotation that is still running. A rotation sent while a blind drives would stop the
163
+ blind where it is. `Destination.cover(<drive action description>)` returns a `Cover`
164
+ with commands that keep the two together:
165
+
166
+ - `move(percentage, rotation=None)`, `open()`, `close()`, `set_rotation(rotation)`,
167
+ `open_slats()`, `close_slats()` and `stop()` send the command,
168
+ update the movement model, store it and return the seconds until the status should be
169
+ requested to check the result. A command that the hub rejects raises a
170
+ `WebControlProError` and leaves the model unchanged.
171
+ `advance()` and `apply_measurement(percentage, rotation)` use the same clock as the
172
+ commands, `apply_measurement` stores a change at once. The hub takes whole numbers, so the percentage and the rotation are
173
+ rounded when they are sent.
174
+ - A rotation while a drive runs is sent together with the drive to its target, so the
175
+ blind keeps driving and turns its slats at the end. A drive counts as running during
176
+ the calculated drive, up to 2 seconds after its calculated end (travel times that are
177
+ a bit too short) and, without a calculated drive, up to 0.5 seconds after the hub
178
+ accepted it. Automations and scenes, for example the scenes of Home Assistant, send
179
+ the drive and the rotation right after each other.
180
+ - A drive within 2 seconds after a rotation sends that rotation again, with the value
181
+ that was sent. This also applies to `open()` and `close()`, which otherwise turn the
182
+ slats to the minimum and the maximum rotation like the hub does.
183
+ - A new drive while a drive with a rotation runs takes that rotation along.
184
+ - `move(percentage, rotation)` sends both in one command.
185
+ - `stop()` stops drive and rotation, the hub has one stop command for both. Nothing that
186
+ was sent before is repeated after a stop.
187
+ - Commands of one destination wait for each other, so the second of two commands that
188
+ arrive together sees the result of the first.
189
+
190
+ The windows are `TravelSettings.combine_window` and
191
+ `TravelSettings.combine_window_untimed`. A drive that the library did not send, for
192
+ example from a wall switch, is not known and not taken along.
193
+
194
+ While a slat drive moves, the model shows the rotation of the direction: the hub turns
195
+ the slats to the minimum rotation before it drives up and to the maximum before it
196
+ drives down. The rotation sent with the drive is shown when the drive ends; without one
197
+ the rotation of the direction stays. A stop leaves the rotation where it is.
163
198
 
164
199
  ## Development
165
200
 
@@ -9,16 +9,14 @@ from .const import (
9
9
  WMS_WebControl_pro_API_actionType,
10
10
  WMS_WebControl_pro_API_responseType,
11
11
  )
12
- from .store import ActionSettings, TravelDirection, valid_percent
12
+ from .store import ActionSettings, TravelDirection
13
13
  from .travel import (
14
14
  CoverModel,
15
15
  Measurement,
16
- closed_tilts,
16
+ closed_rotations,
17
17
  open_rotation,
18
- open_tilt,
19
- rotation_to_tilt,
20
- tilt_angles,
21
- tilt_to_rotation,
18
+ valid_percentage,
19
+ valid_rotation,
22
20
  )
23
21
 
24
22
  if TYPE_CHECKING:
@@ -170,13 +168,11 @@ class Action:
170
168
  self._overwrites[_MAX_VALUE] = rotation
171
169
 
172
170
  def _restore_model(self, state: dict[str, Any]) -> None:
173
- tilt = valid_percent(state.get("tilt"))
174
- target_tilt = valid_percent(state.get("target_tilt"))
175
171
  self.model.restore(
176
- valid_percent(state.get("position")),
177
- None if tilt is None else int(tilt),
178
- valid_percent(state.get("target_position")),
179
- None if target_tilt is None else int(target_tilt),
172
+ valid_percentage(state.get("percentage")),
173
+ valid_rotation(state.get("rotation")),
174
+ valid_percentage(state.get("target_percentage")),
175
+ valid_rotation(state.get("target_rotation")),
180
176
  )
181
177
 
182
178
  def _publish(self) -> None:
@@ -239,55 +235,46 @@ class Action:
239
235
  self._overwrites.pop(_MAX_VALUE, None)
240
236
  await self.sync()
241
237
 
242
- def rotation_to_tilt(self, rotation: float) -> int:
243
- """Convert a rotation to a tilt (0 closed, 100 open) with the limits in use."""
244
- return rotation_to_tilt(rotation, *self.rotation_range)
245
-
246
- def tilt_to_rotation(self, tilt: float) -> int:
247
- """Convert a tilt (0 closed, 100 open) to a rotation with the limits in use."""
248
- return tilt_to_rotation(tilt, *self.rotation_range)
249
-
250
238
  @property
251
239
  def open_rotation(self) -> int:
252
240
  """Return the rotation of open slats, closest to 0 within the limits in use."""
253
241
  return open_rotation(*self.rotation_range)
254
242
 
255
243
  @property
256
- def open_tilt(self) -> int:
257
- """Return the tilt of open slats with the limits in use."""
258
- return open_tilt(*self.rotation_range)
259
-
260
- @property
261
- def closed_tilts(self) -> list[int]:
262
- """Return the tilts of closed slats with the limits in use, see closed_tilts."""
263
- return closed_tilts(*self.rotation_range)
244
+ def closed_rotations(self) -> list[int]:
245
+ """Return the rotations of closed slats with the limits in use.
264
246
 
265
- @property
266
- def tilt_angles(self) -> tuple[int, int] | None:
267
- """Return the slat angles in degrees at tilt 0 and at tilt 100.
268
-
269
- None if the limits in use do not give two different angles.
247
+ See closed_rotations in travel.py, the first is the one to close to.
270
248
  """
271
- return tilt_angles(*self.rotation_range)
249
+ return closed_rotations(*self.rotation_range)
272
250
 
273
- def start_move(self, now: float, target: float, tilt: int | None = None) -> float:
274
- """Handle an accepted drive command with the stored travel times.
275
-
276
- Returns the delay in seconds until the settle poll.
251
+ def start_move(
252
+ self,
253
+ now: float,
254
+ target: float,
255
+ rotation: int | None = None,
256
+ *,
257
+ rotation_range: tuple[float, float] | None = None,
258
+ ) -> float:
259
+ """Handle an accepted drive command to a percentage with the stored travel times.
260
+
261
+ See CoverModel.start_move. Returns the delay in seconds until the
262
+ settle poll.
277
263
  """
278
264
  return self.model.start_move(
279
265
  now,
280
266
  target,
281
267
  self._settings.travel_time(TravelDirection.OPEN),
282
268
  self._settings.travel_time(TravelDirection.CLOSE),
283
- tilt,
269
+ rotation,
270
+ rotation_range=rotation_range,
284
271
  )
285
272
 
286
273
  def apply_measurement(
287
- self, now: float, position: int | None, tilt: int | None
274
+ self, now: float, percentage: float | None, rotation: int | None
288
275
  ) -> Measurement:
289
- """Take over a measured position or tilt unless a drive is running."""
290
- return self.model.apply_measurement(now, position, tilt)
276
+ """Take over a measured percentage or rotation unless a drive is running."""
277
+ return self.model.apply_measurement(now, percentage, rotation)
291
278
 
292
279
  async def sync(self) -> None:
293
280
  """Store changes of overwrites, settings and state.
@@ -0,0 +1,183 @@
1
+ """Commands of a cover that keep a running drive and its rotation together.
2
+
3
+ The hub runs only the last command of a destination and aborts a running one.
4
+ A rotation during a drive is therefore sent together with the drive to its
5
+ target, and a drive soon after a rotation repeats the rotation. Commands of
6
+ one destination are sent one after the other, so each one sees the result of
7
+ the one before.
8
+ """
9
+
10
+ import asyncio
11
+ import math
12
+ from time import monotonic
13
+ from typing import TYPE_CHECKING
14
+
15
+ from .action import Action, ActionList
16
+ from .const import (
17
+ WMS_WebControl_pro_API_actionDescription,
18
+ WMS_WebControl_pro_API_actionType,
19
+ WMS_WebControl_pro_API_responseType,
20
+ )
21
+ from .travel import CoverModel, Measurement
22
+
23
+ if TYPE_CHECKING:
24
+ from .destination import Destination
25
+
26
+
27
+ class Cover:
28
+ """A drive action of a destination and, for a slat drive, its rotation.
29
+
30
+ Units are those of the hub: the percentage of the drive is 0 open and 100
31
+ closed, the rotation is in degrees. Every command returns the delay in
32
+ seconds until the status should be requested to check the result. A
33
+ command that the hub rejects raises a WebControlProError and leaves the
34
+ model unchanged.
35
+ """
36
+
37
+ def __init__(
38
+ self, dest: Destination, drive: Action, rotation: Action | None
39
+ ) -> None:
40
+ """Create the commands, see Destination.cover."""
41
+ self._dest = dest
42
+ self._drive = drive
43
+ self._rotation = rotation
44
+ self._lock: asyncio.Lock = dest._command_lock
45
+
46
+ @property
47
+ def drive(self) -> Action:
48
+ """Return the drive action."""
49
+ return self._drive
50
+
51
+ @property
52
+ def rotation(self) -> Action | None:
53
+ """Return the rotation action of a slat drive, else None."""
54
+ return self._rotation
55
+
56
+ @property
57
+ def model(self) -> CoverModel:
58
+ """Return the movement model of the drive."""
59
+ return self._drive.model
60
+
61
+ def advance(self) -> bool:
62
+ """Move the displayed percentage to now, True if a drive ended with it."""
63
+ return self.model.advance(monotonic())
64
+
65
+ async def apply_measurement(
66
+ self, percentage: float | None, rotation: int | None
67
+ ) -> Measurement:
68
+ """Take over a measured percentage or rotation unless a drive is running.
69
+
70
+ A change is stored at once, so the state after a restart is the
71
+ measured one even when no command or status request follows.
72
+ """
73
+ result = self._drive.apply_measurement(monotonic(), percentage, rotation)
74
+ await self._drive.sync()
75
+ return result
76
+
77
+ async def move(self, percentage: float, rotation: float | None = None) -> float:
78
+ """Drive to a percentage (0 open, 100 closed) and, if given, turn the slats.
79
+
80
+ Without a rotation, a slat drive sends the first of these: the
81
+ rotation sent within combine_window, the minimum rotation when it
82
+ opens fully and the maximum when it closes fully like the hub does,
83
+ the rotation of the running drive. A rotation for a drive without
84
+ slats raises NotImplementedError.
85
+ """
86
+ async with self._lock:
87
+ turn: int | None = None
88
+ remember = False
89
+ if rotation is not None:
90
+ self._require_rotation()
91
+ turn, remember = round(rotation), True
92
+ elif self._rotation is not None:
93
+ turn = self._rotation_for_move(percentage)
94
+ return await self._move(percentage, turn, remember)
95
+
96
+ async def open(self) -> float:
97
+ """Open the cover, drive to 0 %."""
98
+ return await self.move(0)
99
+
100
+ async def close(self) -> float:
101
+ """Close the cover, drive to 100 %."""
102
+ return await self.move(100)
103
+
104
+ async def set_rotation(self, rotation: float) -> float:
105
+ """Turn the slats to a rotation in degrees."""
106
+ self._require_rotation()
107
+ return await self._turn(round(rotation))
108
+
109
+ async def open_slats(self) -> float:
110
+ """Turn the slats to the open rotation of the limits in use."""
111
+ return await self._turn(self._require_rotation().open_rotation)
112
+
113
+ async def close_slats(self) -> float:
114
+ """Turn the slats to the first closed rotation of the limits in use."""
115
+ return await self._turn(self._require_rotation().closed_rotations[0])
116
+
117
+ async def stop(self) -> float:
118
+ """Stop the drive and the rotation, the hub has one stop for both."""
119
+ action = self._dest.action(
120
+ WMS_WebControl_pro_API_actionDescription.ManualCommand,
121
+ WMS_WebControl_pro_API_actionType.Stop,
122
+ )
123
+ async with self._lock:
124
+ await action.prep()(
125
+ responseType=WMS_WebControl_pro_API_responseType.Detailed
126
+ )
127
+ delay = self.model.stop(monotonic())
128
+ await self._drive.sync()
129
+ return delay
130
+
131
+ def _require_rotation(self) -> Action:
132
+ if self._rotation is None:
133
+ raise NotImplementedError(f"{self._drive} of {self._dest} cannot rotate")
134
+ return self._rotation
135
+
136
+ def _rotation_for_move(self, percentage: float) -> int | None:
137
+ """Return the rotation to send with a drive that brings none."""
138
+ if (recent := self.model.recent_rotation(monotonic())) is not None:
139
+ return recent
140
+ minimum, maximum = self._require_rotation().rotation_range
141
+ if percentage == 0:
142
+ return math.floor(minimum + 0.5)
143
+ if percentage == 100:
144
+ return math.floor(maximum + 0.5)
145
+ return self.model.pending_rotation
146
+
147
+ async def _move(
148
+ self, percentage: float, rotation: int | None, remember: bool
149
+ ) -> float:
150
+ await self._send(percentage, rotation)
151
+ now = monotonic()
152
+ delay = self._drive.start_move(
153
+ now,
154
+ percentage,
155
+ rotation,
156
+ rotation_range=(
157
+ None if self._rotation is None else self._rotation.rotation_range
158
+ ),
159
+ )
160
+ if remember and rotation is not None:
161
+ self.model.remember_rotation(now, rotation)
162
+ await self._drive.sync()
163
+ return delay
164
+
165
+ async def _turn(self, rotation: int) -> float:
166
+ async with self._lock:
167
+ target = self.model.drive_target
168
+ if target is not None and self.model.drive_running(monotonic()):
169
+ return await self._move(target, rotation, True)
170
+ await self._send(None, rotation)
171
+ now = monotonic()
172
+ delay = self.model.set_rotation(now, rotation)
173
+ self.model.remember_rotation(now, rotation)
174
+ await self._drive.sync()
175
+ return delay
176
+
177
+ async def _send(self, percentage: float | None, rotation: int | None) -> None:
178
+ actions = ActionList(self._dest._control)
179
+ if percentage is not None:
180
+ actions += self._drive.prep(percentage=round(percentage))
181
+ if rotation is not None:
182
+ actions += self._require_rotation().prep(rotation=rotation)
183
+ await actions()