pywmswebcontrolpro 0.5.0__tar.gz → 0.7.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.5.0 → pywmswebcontrolpro-0.7.0}/CHANGELOG.md +59 -1
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/PKG-INFO +71 -12
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/README.md +70 -11
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/action.py +40 -21
- pywmswebcontrolpro-0.7.0/pywmswebcontrolpro/cover.py +177 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/destination.py +26 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/store.py +0 -7
- pywmswebcontrolpro-0.7.0/pywmswebcontrolpro/travel.py +383 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/conftest.py +8 -2
- pywmswebcontrolpro-0.7.0/tests/test_cover.py +457 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_rotation.py +77 -31
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_settings.py +26 -25
- pywmswebcontrolpro-0.7.0/tests/test_travel.py +400 -0
- pywmswebcontrolpro-0.5.0/pywmswebcontrolpro/travel.py +0 -285
- pywmswebcontrolpro-0.5.0/tests/test_travel.py +0 -225
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/.gitignore +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/.python-version +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/LICENSE +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/webcontrol.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.5.0 → pywmswebcontrolpro-0.7.0}/tests/test_refresh.py +0 -0
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.7.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
Breaking changes:
|
|
6
|
+
|
|
7
|
+
- The library uses the values of the hub only: the percentage of a drive (0 open, 100
|
|
8
|
+
closed) and the rotation of slats in degrees. The position and tilt of Home
|
|
9
|
+
Assistant (0 to 100) are converted by the application.
|
|
10
|
+
- `CoverModel` keeps `percentage` and `rotation` instead of `position` and `tilt`,
|
|
11
|
+
`percentage_int` replaces `position_int`, `set_rotation` replaces `set_tilt`.
|
|
12
|
+
`start_move` takes the rotation for the end of the drive and the `rotation_range` of
|
|
13
|
+
slats instead of `tilt`, `rotation` and `slats`. `Action.start_move` and
|
|
14
|
+
`apply_measurement` take a percentage and a rotation.
|
|
15
|
+
- `TravelSettings.settle_tilt` is now `settle_rotation`, `position_tolerance` is now
|
|
16
|
+
`percentage_tolerance`.
|
|
17
|
+
- Removed: `wms_percentage_to_position`, `rotation_to_tilt`, `tilt_to_rotation`,
|
|
18
|
+
`open_tilt`, `closed_tilts`, `rotation_to_angle` and `tilt_angles` in `travel.py`,
|
|
19
|
+
and `Action.rotation_to_tilt`, `Action.tilt_to_rotation`, `Action.open_tilt`,
|
|
20
|
+
`Action.closed_tilts` and `Action.tilt_angles`. `valid_percent` in `store.py` is now
|
|
21
|
+
`valid_percentage` in `travel.py`.
|
|
22
|
+
- `state.json` stores `percentage`, `rotation`, `target_percentage` and
|
|
23
|
+
`target_rotation`. The state stored by 0.6.0 is not read, the next status request
|
|
24
|
+
measures it again. Settings and rotation limits stay.
|
|
25
|
+
|
|
26
|
+
Added:
|
|
27
|
+
|
|
28
|
+
- `Destination.cover()` returns a `Cover` with the commands of a drive and its rotation:
|
|
29
|
+
`move`, `open`, `close`, `set_rotation`, `open_slats`, `close_slats` and `stop`, plus
|
|
30
|
+
`advance` and `apply_measurement` with the same clock. They send the command, update
|
|
31
|
+
and store the movement model and return the delay until the status should be
|
|
32
|
+
checked, see the README.
|
|
33
|
+
- A rotation during a running drive is sent together with the drive to its target, and a
|
|
34
|
+
drive within 2 seconds after a rotation repeats it. The hub runs only the last command
|
|
35
|
+
of a destination, so until now the rotation stopped the drive.
|
|
36
|
+
- Commands of one destination are sent one after the other.
|
|
37
|
+
- `Action.closed_rotations` and `closed_rotations` in `travel.py`, the rotations of
|
|
38
|
+
closed slats with the limits in use, and `valid_rotation`.
|
|
39
|
+
- `CoverModel.drive_running`, `CoverModel.drive_target`, `CoverModel.pending_rotation`,
|
|
40
|
+
`CoverModel.remember_rotation`, `CoverModel.recent_rotation` and the settings
|
|
41
|
+
`TravelSettings.combine_window` (2 seconds) and
|
|
42
|
+
`TravelSettings.combine_window_untimed` (0.5 seconds).
|
|
43
|
+
|
|
44
|
+
Changed:
|
|
45
|
+
|
|
46
|
+
- With the `rotation_range` of slats (set by `Cover` for slat drives)
|
|
47
|
+
`CoverModel.start_move` shows the rotation of the direction while the drive runs, the
|
|
48
|
+
minimum up and the maximum down, and keeps it after a drive without a rotation and
|
|
49
|
+
after a stop.
|
|
50
|
+
|
|
51
|
+
## 0.6.0
|
|
52
|
+
|
|
53
|
+
Added:
|
|
54
|
+
|
|
55
|
+
- Tilt model of slat drives for the cover tilt of Home Assistant 2026.12, see the
|
|
56
|
+
README: `Action.open_rotation`, `Action.open_tilt`, `Action.closed_tilts` and
|
|
57
|
+
`Action.tilt_angles`, calculated with the rotation limits in use. The functions
|
|
58
|
+
`open_rotation`, `open_tilt`, `closed_tilts`, `rotation_to_angle` and `tilt_angles`
|
|
59
|
+
in `travel.py` take the limits as arguments.
|
|
60
|
+
|
|
61
|
+
## 0.5.0
|
|
4
62
|
|
|
5
63
|
Added:
|
|
6
64
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pywmswebcontrolpro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.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
|
|
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`, `
|
|
126
|
-
replaced by
|
|
127
|
-
the drive action, an awning and its valance, which share a
|
|
128
|
-
independently. After a restart the
|
|
129
|
-
`restored` until a measurement arrives.
|
|
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
|
|
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,13 +149,67 @@ 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
|
|
|
156
|
+
## Open and closed slats
|
|
157
|
+
|
|
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
|
+
|
|
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.
|
|
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. 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.
|
|
212
|
+
|
|
154
213
|
## Development
|
|
155
214
|
|
|
156
215
|
```bash
|
|
@@ -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
|
|
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`, `
|
|
112
|
-
replaced by
|
|
113
|
-
the drive action, an awning and its valance, which share a
|
|
114
|
-
independently. After a restart the
|
|
115
|
-
`restored` until a measurement arrives.
|
|
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
|
|
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,13 +135,67 @@ 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
|
|
|
142
|
+
## Open and closed slats
|
|
143
|
+
|
|
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
|
+
|
|
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.
|
|
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. 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.
|
|
198
|
+
|
|
140
199
|
## Development
|
|
141
200
|
|
|
142
201
|
```bash
|
|
@@ -9,8 +9,15 @@ 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
|
|
13
|
-
from .travel import
|
|
12
|
+
from .store import ActionSettings, TravelDirection
|
|
13
|
+
from .travel import (
|
|
14
|
+
CoverModel,
|
|
15
|
+
Measurement,
|
|
16
|
+
closed_rotations,
|
|
17
|
+
open_rotation,
|
|
18
|
+
valid_percentage,
|
|
19
|
+
valid_rotation,
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
if TYPE_CHECKING:
|
|
16
23
|
from .destination import Destination
|
|
@@ -161,13 +168,11 @@ class Action:
|
|
|
161
168
|
self._overwrites[_MAX_VALUE] = rotation
|
|
162
169
|
|
|
163
170
|
def _restore_model(self, state: dict[str, Any]) -> None:
|
|
164
|
-
tilt = valid_percent(state.get("tilt"))
|
|
165
|
-
target_tilt = valid_percent(state.get("target_tilt"))
|
|
166
171
|
self.model.restore(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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")),
|
|
171
176
|
)
|
|
172
177
|
|
|
173
178
|
def _publish(self) -> None:
|
|
@@ -230,32 +235,46 @@ class Action:
|
|
|
230
235
|
self._overwrites.pop(_MAX_VALUE, None)
|
|
231
236
|
await self.sync()
|
|
232
237
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
@property
|
|
239
|
+
def open_rotation(self) -> int:
|
|
240
|
+
"""Return the rotation of open slats, closest to 0 within the limits in use."""
|
|
241
|
+
return open_rotation(*self.rotation_range)
|
|
236
242
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
243
|
+
@property
|
|
244
|
+
def closed_rotations(self) -> list[int]:
|
|
245
|
+
"""Return the rotations of closed slats with the limits in use.
|
|
240
246
|
|
|
241
|
-
|
|
242
|
-
"""
|
|
247
|
+
See closed_rotations in travel.py, the first is the one to close to.
|
|
248
|
+
"""
|
|
249
|
+
return closed_rotations(*self.rotation_range)
|
|
243
250
|
|
|
244
|
-
|
|
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.
|
|
245
263
|
"""
|
|
246
264
|
return self.model.start_move(
|
|
247
265
|
now,
|
|
248
266
|
target,
|
|
249
267
|
self._settings.travel_time(TravelDirection.OPEN),
|
|
250
268
|
self._settings.travel_time(TravelDirection.CLOSE),
|
|
251
|
-
|
|
269
|
+
rotation,
|
|
270
|
+
rotation_range=rotation_range,
|
|
252
271
|
)
|
|
253
272
|
|
|
254
273
|
def apply_measurement(
|
|
255
|
-
self, now: float,
|
|
274
|
+
self, now: float, percentage: float | None, rotation: int | None
|
|
256
275
|
) -> Measurement:
|
|
257
|
-
"""Take over a measured
|
|
258
|
-
return self.model.apply_measurement(now,
|
|
276
|
+
"""Take over a measured percentage or rotation unless a drive is running."""
|
|
277
|
+
return self.model.apply_measurement(now, percentage, rotation)
|
|
259
278
|
|
|
260
279
|
async def sync(self) -> None:
|
|
261
280
|
"""Store changes of overwrites, settings and state.
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
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
|
+
return self._drive.apply_measurement(monotonic(), percentage, rotation)
|
|
70
|
+
|
|
71
|
+
async def move(self, percentage: float, rotation: float | None = None) -> float:
|
|
72
|
+
"""Drive to a percentage (0 open, 100 closed) and, if given, turn the slats.
|
|
73
|
+
|
|
74
|
+
Without a rotation, a slat drive sends the first of these: the
|
|
75
|
+
rotation sent within combine_window, the minimum rotation when it
|
|
76
|
+
opens fully and the maximum when it closes fully like the hub does,
|
|
77
|
+
the rotation of the running drive. A rotation for a drive without
|
|
78
|
+
slats raises NotImplementedError.
|
|
79
|
+
"""
|
|
80
|
+
async with self._lock:
|
|
81
|
+
turn: int | None = None
|
|
82
|
+
remember = False
|
|
83
|
+
if rotation is not None:
|
|
84
|
+
self._require_rotation()
|
|
85
|
+
turn, remember = round(rotation), True
|
|
86
|
+
elif self._rotation is not None:
|
|
87
|
+
turn = self._rotation_for_move(percentage)
|
|
88
|
+
return await self._move(percentage, turn, remember)
|
|
89
|
+
|
|
90
|
+
async def open(self) -> float:
|
|
91
|
+
"""Open the cover, drive to 0 %."""
|
|
92
|
+
return await self.move(0)
|
|
93
|
+
|
|
94
|
+
async def close(self) -> float:
|
|
95
|
+
"""Close the cover, drive to 100 %."""
|
|
96
|
+
return await self.move(100)
|
|
97
|
+
|
|
98
|
+
async def set_rotation(self, rotation: float) -> float:
|
|
99
|
+
"""Turn the slats to a rotation in degrees."""
|
|
100
|
+
self._require_rotation()
|
|
101
|
+
return await self._turn(round(rotation))
|
|
102
|
+
|
|
103
|
+
async def open_slats(self) -> float:
|
|
104
|
+
"""Turn the slats to the open rotation of the limits in use."""
|
|
105
|
+
return await self._turn(self._require_rotation().open_rotation)
|
|
106
|
+
|
|
107
|
+
async def close_slats(self) -> float:
|
|
108
|
+
"""Turn the slats to the first closed rotation of the limits in use."""
|
|
109
|
+
return await self._turn(self._require_rotation().closed_rotations[0])
|
|
110
|
+
|
|
111
|
+
async def stop(self) -> float:
|
|
112
|
+
"""Stop the drive and the rotation, the hub has one stop for both."""
|
|
113
|
+
action = self._dest.action(
|
|
114
|
+
WMS_WebControl_pro_API_actionDescription.ManualCommand,
|
|
115
|
+
WMS_WebControl_pro_API_actionType.Stop,
|
|
116
|
+
)
|
|
117
|
+
async with self._lock:
|
|
118
|
+
await action.prep()(
|
|
119
|
+
responseType=WMS_WebControl_pro_API_responseType.Detailed
|
|
120
|
+
)
|
|
121
|
+
delay = self.model.stop(monotonic())
|
|
122
|
+
await self._drive.sync()
|
|
123
|
+
return delay
|
|
124
|
+
|
|
125
|
+
def _require_rotation(self) -> Action:
|
|
126
|
+
if self._rotation is None:
|
|
127
|
+
raise NotImplementedError(f"{self._drive} of {self._dest} cannot rotate")
|
|
128
|
+
return self._rotation
|
|
129
|
+
|
|
130
|
+
def _rotation_for_move(self, percentage: float) -> int | None:
|
|
131
|
+
"""Return the rotation to send with a drive that brings none."""
|
|
132
|
+
if (recent := self.model.recent_rotation(monotonic())) is not None:
|
|
133
|
+
return recent
|
|
134
|
+
minimum, maximum = self._require_rotation().rotation_range
|
|
135
|
+
if percentage == 0:
|
|
136
|
+
return math.floor(minimum + 0.5)
|
|
137
|
+
if percentage == 100:
|
|
138
|
+
return math.floor(maximum + 0.5)
|
|
139
|
+
return self.model.pending_rotation
|
|
140
|
+
|
|
141
|
+
async def _move(
|
|
142
|
+
self, percentage: float, rotation: int | None, remember: bool
|
|
143
|
+
) -> float:
|
|
144
|
+
await self._send(percentage, rotation)
|
|
145
|
+
now = monotonic()
|
|
146
|
+
delay = self._drive.start_move(
|
|
147
|
+
now,
|
|
148
|
+
percentage,
|
|
149
|
+
rotation,
|
|
150
|
+
rotation_range=(
|
|
151
|
+
None if self._rotation is None else self._rotation.rotation_range
|
|
152
|
+
),
|
|
153
|
+
)
|
|
154
|
+
if remember and rotation is not None:
|
|
155
|
+
self.model.remember_rotation(now, rotation)
|
|
156
|
+
await self._drive.sync()
|
|
157
|
+
return delay
|
|
158
|
+
|
|
159
|
+
async def _turn(self, rotation: int) -> float:
|
|
160
|
+
async with self._lock:
|
|
161
|
+
target = self.model.drive_target
|
|
162
|
+
if target is not None and self.model.drive_running(monotonic()):
|
|
163
|
+
return await self._move(target, rotation, True)
|
|
164
|
+
await self._send(None, rotation)
|
|
165
|
+
now = monotonic()
|
|
166
|
+
delay = self.model.set_rotation(now, rotation)
|
|
167
|
+
self.model.remember_rotation(now, rotation)
|
|
168
|
+
await self._drive.sync()
|
|
169
|
+
return delay
|
|
170
|
+
|
|
171
|
+
async def _send(self, percentage: float | None, rotation: int | None) -> None:
|
|
172
|
+
actions = ActionList(self._dest._control)
|
|
173
|
+
if percentage is not None:
|
|
174
|
+
actions += self._drive.prep(percentage=round(percentage))
|
|
175
|
+
if rotation is not None:
|
|
176
|
+
actions += self._require_rotation().prep(rotation=rotation)
|
|
177
|
+
await actions()
|
|
@@ -14,6 +14,7 @@ from .const import (
|
|
|
14
14
|
WMS_WebControl_pro_API_animationType,
|
|
15
15
|
WMS_WebControl_pro_API_drivingCause,
|
|
16
16
|
)
|
|
17
|
+
from .cover import Cover
|
|
17
18
|
from .exceptions import WebControlProError
|
|
18
19
|
from .refresh import (
|
|
19
20
|
ERROR_RADIO_BUSY,
|
|
@@ -57,6 +58,10 @@ class Destination:
|
|
|
57
58
|
self._blocking = None
|
|
58
59
|
self._status: dict[str, Any] = {}
|
|
59
60
|
self._stats = RefreshStats(window=control.stats_window.total_seconds())
|
|
61
|
+
# The hub runs only the last command of a destination, its commands
|
|
62
|
+
# are sent one after the other.
|
|
63
|
+
self._command_lock = asyncio.Lock()
|
|
64
|
+
self._covers: dict[int, Cover] = {}
|
|
60
65
|
|
|
61
66
|
def __str__(self) -> str:
|
|
62
67
|
return self.name
|
|
@@ -283,6 +288,27 @@ class Destination:
|
|
|
283
288
|
f"and type {type_name} in {self} ({self._id})"
|
|
284
289
|
)
|
|
285
290
|
|
|
291
|
+
def cover(
|
|
292
|
+
self, actionDescription: WMS_WebControl_pro_API_actionDescription
|
|
293
|
+
) -> Cover:
|
|
294
|
+
"""Return the commands of the cover moved by the matching drive action.
|
|
295
|
+
|
|
296
|
+
A slat drive gets the rotation of the destination as well. Raises
|
|
297
|
+
NotImplementedError if the destination has no such drive.
|
|
298
|
+
"""
|
|
299
|
+
drive = self.action(actionDescription)
|
|
300
|
+
if (cover := self._covers.get(drive.id)) is None:
|
|
301
|
+
rotation = None
|
|
302
|
+
if (
|
|
303
|
+
actionDescription is WMS_WebControl_pro_API_actionDescription.SlatDrive
|
|
304
|
+
and self.hasAction(WMS_WebControl_pro_API_actionDescription.SlatRotate)
|
|
305
|
+
):
|
|
306
|
+
rotation = self.action(
|
|
307
|
+
WMS_WebControl_pro_API_actionDescription.SlatRotate
|
|
308
|
+
)
|
|
309
|
+
cover = self._covers[drive.id] = Cover(self, drive, rotation)
|
|
310
|
+
return cover
|
|
311
|
+
|
|
286
312
|
def diag(self) -> dict[str, Any]:
|
|
287
313
|
"""Return the destination for the diagnostics."""
|
|
288
314
|
return {
|
|
@@ -57,13 +57,6 @@ class ActionSettings:
|
|
|
57
57
|
return cls(**{f.name: _valid_seconds(data.get(f.name)) for f in fields(cls)})
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
def valid_percent(value: Any) -> float | None:
|
|
61
|
-
"""Return a stored position or tilt, None if it is no number from 0 to 100."""
|
|
62
|
-
if isinstance(value, bool) or not isinstance(value, int | float):
|
|
63
|
-
return None
|
|
64
|
-
return float(value) if 0 <= value <= 100 else None
|
|
65
|
-
|
|
66
|
-
|
|
67
60
|
def _valid_seconds(value: Any) -> float:
|
|
68
61
|
if isinstance(value, bool) or not isinstance(value, int | float):
|
|
69
62
|
return 0.0
|