pywmswebcontrolpro 0.6.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.6.0 → pywmswebcontrolpro-0.7.0}/CHANGELOG.md +48 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/PKG-INFO +67 -32
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/README.md +66 -31
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/action.py +29 -42
- pywmswebcontrolpro-0.7.0/pywmswebcontrolpro/cover.py +177 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/destination.py +26 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/store.py +0 -7
- pywmswebcontrolpro-0.7.0/pywmswebcontrolpro/travel.py +383 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/conftest.py +8 -2
- pywmswebcontrolpro-0.7.0/tests/test_cover.py +457 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_rotation.py +34 -112
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_settings.py +26 -25
- pywmswebcontrolpro-0.7.0/tests/test_travel.py +400 -0
- pywmswebcontrolpro-0.6.0/pywmswebcontrolpro/travel.py +0 -338
- pywmswebcontrolpro-0.6.0/tests/test_travel.py +0 -225
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/.gitignore +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/.python-version +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/LICENSE +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/pywmswebcontrolpro/webcontrol.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.6.0 → pywmswebcontrolpro-0.7.0}/tests/test_refresh.py +0 -0
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
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
|
+
|
|
3
51
|
## 0.6.0
|
|
4
52
|
|
|
5
53
|
Added:
|
|
@@ -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,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
|
-
##
|
|
156
|
+
## Open and closed slats
|
|
155
157
|
|
|
156
|
-
|
|
157
|
-
|
|
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.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
The
|
|
176
|
-
|
|
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.
|
|
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
|
|
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,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
|
-
##
|
|
142
|
+
## Open and closed slats
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
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.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
The
|
|
162
|
-
|
|
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.
|
|
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
|
|
12
|
+
from .store import ActionSettings, TravelDirection
|
|
13
13
|
from .travel import (
|
|
14
14
|
CoverModel,
|
|
15
15
|
Measurement,
|
|
16
|
-
|
|
16
|
+
closed_rotations,
|
|
17
17
|
open_rotation,
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
|
257
|
-
"""Return the
|
|
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
|
-
|
|
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
|
|
249
|
+
return closed_rotations(*self.rotation_range)
|
|
272
250
|
|
|
273
|
-
def start_move(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
269
|
+
rotation,
|
|
270
|
+
rotation_range=rotation_range,
|
|
284
271
|
)
|
|
285
272
|
|
|
286
273
|
def apply_measurement(
|
|
287
|
-
self, now: float,
|
|
274
|
+
self, now: float, percentage: float | None, rotation: int | None
|
|
288
275
|
) -> Measurement:
|
|
289
|
-
"""Take over a measured
|
|
290
|
-
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)
|
|
291
278
|
|
|
292
279
|
async def sync(self) -> None:
|
|
293
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()
|