pywmswebcontrolpro 0.2.1__tar.gz → 0.4.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.2.1 → pywmswebcontrolpro-0.4.0}/CHANGELOG.md +44 -1
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/PKG-INFO +38 -14
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/README.md +37 -13
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/action.py +38 -79
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/destination.py +3 -4
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/refresh.py +20 -0
- pywmswebcontrolpro-0.4.0/pywmswebcontrolpro/store.py +249 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/webcontrol.py +16 -5
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/conftest.py +13 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_refresh.py +42 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_rotation.py +5 -5
- pywmswebcontrolpro-0.4.0/tests/test_settings.py +573 -0
- pywmswebcontrolpro-0.2.1/pywmswebcontrolpro/store.py +0 -135
- pywmswebcontrolpro-0.2.1/tests/test_settings.py +0 -378
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/.gitignore +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/.python-version +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/LICENSE +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/pywmswebcontrolpro/travel.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.2.1 → pywmswebcontrolpro-0.4.0}/tests/test_travel.py +0 -0
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.4.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
Breaking changes:
|
|
6
|
+
|
|
7
|
+
- The stored data is kept for each destination instead of for the whole hub:
|
|
8
|
+
`<destination id>/settings.json` and `<destination id>/state.json` in the persist
|
|
9
|
+
directory, with an entry for each action below `actions`. The files `settings.json`
|
|
10
|
+
and `state.json` of 0.3.0 in the persist directory itself are not read and not
|
|
11
|
+
removed, travel times and changed rotation limits have to be set again.
|
|
12
|
+
|
|
13
|
+
Changed:
|
|
14
|
+
|
|
15
|
+
- A change only writes the file of its destination.
|
|
16
|
+
- A file without entries is removed, and with the last file the directory of the
|
|
17
|
+
destination.
|
|
18
|
+
- The files of a destination are read when `WebControlPro.refresh()` creates it.
|
|
19
|
+
|
|
20
|
+
## 0.3.0
|
|
21
|
+
|
|
22
|
+
Breaking changes:
|
|
23
|
+
|
|
24
|
+
- The stored data of all actions of a hub is kept in two files of the persist
|
|
25
|
+
directory, `settings.json` (travel times and overwrites) and `state.json` (last known
|
|
26
|
+
position and tilt), instead of one file for each action
|
|
27
|
+
(`<destination id>/<action id>.json`). The old files are not read and not removed,
|
|
28
|
+
travel times and changed rotation limits have to be set again.
|
|
29
|
+
- `JsonStore` is replaced by `HubStore`, the store of a client that reads the files
|
|
30
|
+
once and is the only place that writes them.
|
|
31
|
+
|
|
32
|
+
Added:
|
|
33
|
+
|
|
34
|
+
- `RefreshStats.success_rate`, the share of refreshes with data in percent, and
|
|
35
|
+
`WebControlPro.stats`, the counters of all destinations together.
|
|
36
|
+
|
|
37
|
+
Changed:
|
|
38
|
+
|
|
39
|
+
- Only data that differs from the defaults is stored, an action without travel times,
|
|
40
|
+
overwrites or a known position has no entry.
|
|
41
|
+
- A drive writes only `state.json`, the settings are written when they change.
|
|
42
|
+
- Changes of several actions of a destination are stored with one write for each file.
|
|
43
|
+
- An action has its stored data as soon as `WebControlPro.refresh()` created it, no
|
|
44
|
+
longer after the first `sync()`.
|
|
45
|
+
|
|
46
|
+
## 0.2.1
|
|
4
47
|
|
|
5
48
|
Changed:
|
|
6
49
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pywmswebcontrolpro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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
|
|
@@ -43,9 +43,11 @@ failure the previous values stay unchanged. The outcome is truthy only for `ok`.
|
|
|
43
43
|
to the hub (default 0.5 seconds).
|
|
44
44
|
|
|
45
45
|
Failed refreshes are counted per destination (`Destination.stats`, also part of
|
|
46
|
-
`diag()`) instead of being logged.
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
`diag()`) instead of being logged. `RefreshStats.success_rate` is the share of
|
|
47
|
+
refreshes with data in percent, `RefreshStats.last_ok` the time of the last one, and
|
|
48
|
+
`WebControlPro.stats` combines all destinations. A warning is logged once when a
|
|
49
|
+
destination has failed continuously for `stale_warning_after` (default 24 hours) and
|
|
50
|
+
once when it delivers data again.
|
|
49
51
|
|
|
50
52
|
## Errors
|
|
51
53
|
|
|
@@ -72,17 +74,39 @@ cannot encrypt or authenticate the connection. Run the gateway in a trusted netw
|
|
|
72
74
|
|
|
73
75
|
## Settings, movement model and stored state
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) stores in it:
|
|
77
|
+
The client keeps the data of the actions in the `persist` directory. Each destination
|
|
78
|
+
has a directory of its own, named by its id, with two files:
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
```
|
|
81
|
+
<persist>/<destination id>/settings.json
|
|
82
|
+
<persist>/<destination id>/state.json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- `settings.json`: what was set or learned and cannot be measured again. For a drive
|
|
86
|
+
action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
|
|
87
|
+
are the travel times for a full drive, open and close, in seconds
|
|
88
|
+
(`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
|
|
89
|
+
of the rotation limits.
|
|
90
|
+
- `state.json`: the last known position and tilt of a drive action and the target of a
|
|
91
|
+
running drive.
|
|
92
|
+
|
|
93
|
+
Both files have an entry for each action of the destination, and only for data that
|
|
94
|
+
differs from the defaults:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{"version": 1, "actions": {"0": {"settings": {"travel_time_open": 39.0, "travel_time_close": 39.0}}, "6": {"overwrites": {"minValue": -70}}}}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
A file without entries is removed, and with the last file the directory of the
|
|
101
|
+
destination.
|
|
82
102
|
|
|
83
|
-
The
|
|
84
|
-
and the
|
|
85
|
-
stored.
|
|
103
|
+
The store of the client (`pywmswebcontrolpro/store.py`) is the only place that reads
|
|
104
|
+
and writes the files. It reads the files of a destination once, when
|
|
105
|
+
`WebControlPro.refresh()` creates it, an action has its stored data from then on.
|
|
106
|
+
Writes are serialized and replace a file atomically, changes that arrive during a write
|
|
107
|
+
are stored together with the next one. A drive only writes the `state.json` of its
|
|
108
|
+
destination. Files of destinations that the hub does not report are not touched.
|
|
109
|
+
Without a persist path nothing is stored.
|
|
86
110
|
|
|
87
111
|
`Action.model` is the movement model of the cover driven by this action: `start_move`,
|
|
88
112
|
`stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
|
|
@@ -106,7 +130,7 @@ The library works around it in `pywmswebcontrolpro/action.py`:
|
|
|
106
130
|
- A rotation that is measured beyond the range in use widens it. The limits of the hub
|
|
107
131
|
themselves (-127 and 127) are never learned.
|
|
108
132
|
- `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
|
|
109
|
-
returns to the default. Both are stored in
|
|
133
|
+
returns to the default. Both are stored in `settings.json`.
|
|
110
134
|
- `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
|
|
111
135
|
use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
|
|
112
136
|
rotation that is sent is a whole number within the limits.
|
|
@@ -29,9 +29,11 @@ failure the previous values stay unchanged. The outcome is truthy only for `ok`.
|
|
|
29
29
|
to the hub (default 0.5 seconds).
|
|
30
30
|
|
|
31
31
|
Failed refreshes are counted per destination (`Destination.stats`, also part of
|
|
32
|
-
`diag()`) instead of being logged.
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
`diag()`) instead of being logged. `RefreshStats.success_rate` is the share of
|
|
33
|
+
refreshes with data in percent, `RefreshStats.last_ok` the time of the last one, and
|
|
34
|
+
`WebControlPro.stats` combines all destinations. A warning is logged once when a
|
|
35
|
+
destination has failed continuously for `stale_warning_after` (default 24 hours) and
|
|
36
|
+
once when it delivers data again.
|
|
35
37
|
|
|
36
38
|
## Errors
|
|
37
39
|
|
|
@@ -58,17 +60,39 @@ cannot encrypt or authenticate the connection. Run the gateway in a trusted netw
|
|
|
58
60
|
|
|
59
61
|
## Settings, movement model and stored state
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
(for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) stores in it:
|
|
63
|
+
The client keeps the data of the actions in the `persist` directory. Each destination
|
|
64
|
+
has a directory of its own, named by its id, with two files:
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
```
|
|
67
|
+
<persist>/<destination id>/settings.json
|
|
68
|
+
<persist>/<destination id>/state.json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- `settings.json`: what was set or learned and cannot be measured again. For a drive
|
|
72
|
+
action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
|
|
73
|
+
are the travel times for a full drive, open and close, in seconds
|
|
74
|
+
(`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
|
|
75
|
+
of the rotation limits.
|
|
76
|
+
- `state.json`: the last known position and tilt of a drive action and the target of a
|
|
77
|
+
running drive.
|
|
78
|
+
|
|
79
|
+
Both files have an entry for each action of the destination, and only for data that
|
|
80
|
+
differs from the defaults:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{"version": 1, "actions": {"0": {"settings": {"travel_time_open": 39.0, "travel_time_close": 39.0}}, "6": {"overwrites": {"minValue": -70}}}}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A file without entries is removed, and with the last file the directory of the
|
|
87
|
+
destination.
|
|
68
88
|
|
|
69
|
-
The
|
|
70
|
-
and the
|
|
71
|
-
stored.
|
|
89
|
+
The store of the client (`pywmswebcontrolpro/store.py`) is the only place that reads
|
|
90
|
+
and writes the files. It reads the files of a destination once, when
|
|
91
|
+
`WebControlPro.refresh()` creates it, an action has its stored data from then on.
|
|
92
|
+
Writes are serialized and replace a file atomically, changes that arrive during a write
|
|
93
|
+
are stored together with the next one. A drive only writes the `state.json` of its
|
|
94
|
+
destination. Files of destinations that the hub does not report are not touched.
|
|
95
|
+
Without a persist path nothing is stored.
|
|
72
96
|
|
|
73
97
|
`Action.model` is the movement model of the cover driven by this action: `start_move`,
|
|
74
98
|
`stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
|
|
@@ -92,7 +116,7 @@ The library works around it in `pywmswebcontrolpro/action.py`:
|
|
|
92
116
|
- A rotation that is measured beyond the range in use widens it. The limits of the hub
|
|
93
117
|
themselves (-127 and 127) are never learned.
|
|
94
118
|
- `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
|
|
95
|
-
returns to the default. Both are stored in
|
|
119
|
+
returns to the default. Both are stored in `settings.json`.
|
|
96
120
|
- `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
|
|
97
121
|
use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
|
|
98
122
|
rotation that is sent is a whole number within the limits.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""An action of a destination with its stored settings and movement model."""
|
|
2
2
|
|
|
3
|
-
import asyncio
|
|
4
3
|
import math
|
|
5
4
|
from dataclasses import asdict, replace
|
|
6
5
|
from typing import TYPE_CHECKING, Any
|
|
@@ -10,21 +9,13 @@ from .const import (
|
|
|
10
9
|
WMS_WebControl_pro_API_actionType,
|
|
11
10
|
WMS_WebControl_pro_API_responseType,
|
|
12
11
|
)
|
|
13
|
-
from .store import
|
|
14
|
-
STORE_VERSION,
|
|
15
|
-
ActionSettings,
|
|
16
|
-
JsonStore,
|
|
17
|
-
TravelDirection,
|
|
18
|
-
valid_percent,
|
|
19
|
-
)
|
|
12
|
+
from .store import ActionSettings, TravelDirection, valid_percent
|
|
20
13
|
from .travel import CoverModel, Measurement, rotation_to_tilt, tilt_to_rotation
|
|
21
14
|
|
|
22
15
|
if TYPE_CHECKING:
|
|
23
16
|
from .destination import Destination
|
|
24
17
|
from .webcontrol import WebControlPro
|
|
25
18
|
|
|
26
|
-
_STORED_KEYS = frozenset({"version", "overwrites", "settings", "state"})
|
|
27
|
-
|
|
28
19
|
# Firmware bug of the WMS WebControl pro: the hub reports the rotation limits
|
|
29
20
|
# of slat drives as -127 and 127, the drives turn from -75 to 75. Warema knows
|
|
30
21
|
# the bug and has not fixed it. While the hub reports exactly these limits,
|
|
@@ -77,10 +68,8 @@ class Action:
|
|
|
77
68
|
) -> None:
|
|
78
69
|
"""Create the action from the configuration of the gateway."""
|
|
79
70
|
self._dest = dest
|
|
80
|
-
# The id becomes part of a file path, so it must be a number.
|
|
81
71
|
self._id = int(id)
|
|
82
|
-
self.
|
|
83
|
-
self._store = JsonStore(self._persist)
|
|
72
|
+
self._store = dest._control._store
|
|
84
73
|
self._actionType = WMS_WebControl_pro_API_actionType(actionType)
|
|
85
74
|
self._actionDescription = WMS_WebControl_pro_API_actionDescription(
|
|
86
75
|
actionDescription
|
|
@@ -88,14 +77,14 @@ class Action:
|
|
|
88
77
|
self._attrs = kwargs
|
|
89
78
|
self._defaults = self._rotation_defaults()
|
|
90
79
|
self._params: dict[str, Any] = {}
|
|
91
|
-
self.
|
|
92
|
-
|
|
93
|
-
self.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
self._settings = ActionSettings()
|
|
97
|
-
self._saved_state: dict[str, Any] | None = None
|
|
80
|
+
stored = self._store.settings(dest.id, self._id)
|
|
81
|
+
overwrites = stored.get("overwrites")
|
|
82
|
+
self._overwrites: dict[str, Any] = (
|
|
83
|
+
overwrites if isinstance(overwrites, dict) else {}
|
|
84
|
+
)
|
|
85
|
+
self._settings = ActionSettings.from_dict(stored.get("settings"))
|
|
98
86
|
self.model = CoverModel()
|
|
87
|
+
self._restore_model(self._store.state(dest.id, self._id))
|
|
99
88
|
|
|
100
89
|
def __str__(self) -> str:
|
|
101
90
|
return self.actionDescription.name
|
|
@@ -168,56 +157,32 @@ class Action:
|
|
|
168
157
|
minimum, maximum = self.rotation_range
|
|
169
158
|
if rotation < minimum:
|
|
170
159
|
self._overwrites[_MIN_VALUE] = rotation
|
|
171
|
-
self._needs_save = True
|
|
172
160
|
elif rotation > maximum:
|
|
173
161
|
self._overwrites[_MAX_VALUE] = rotation
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
self.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
state = self.model.snapshot()
|
|
198
|
-
# Cleared before the write, so a change made during it is stored next.
|
|
199
|
-
self._needs_save = False
|
|
200
|
-
saved = await self._store.save(
|
|
201
|
-
{
|
|
202
|
-
**self._extra,
|
|
203
|
-
"version": STORE_VERSION,
|
|
204
|
-
"overwrites": self._overwrites,
|
|
205
|
-
"settings": asdict(self._settings),
|
|
206
|
-
"state": state,
|
|
207
|
-
}
|
|
162
|
+
|
|
163
|
+
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
|
+
self.model.restore(
|
|
167
|
+
valid_percent(state.get("position")),
|
|
168
|
+
None if tilt is None else int(tilt),
|
|
169
|
+
valid_percent(state.get("target_position")),
|
|
170
|
+
None if target_tilt is None else int(target_tilt),
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
def _publish(self) -> None:
|
|
174
|
+
"""Hand the data that differs from the defaults to the store."""
|
|
175
|
+
settings: dict[str, Any] = {}
|
|
176
|
+
if self._overwrites:
|
|
177
|
+
settings["overwrites"] = self._overwrites
|
|
178
|
+
if self._settings != ActionSettings():
|
|
179
|
+
settings["settings"] = asdict(self._settings)
|
|
180
|
+
self._store.set_settings(self._dest.id, self._id, settings)
|
|
181
|
+
self._store.set_state(
|
|
182
|
+
self._dest.id,
|
|
183
|
+
self._id,
|
|
184
|
+
{k: v for k, v in self.model.snapshot().items() if v is not None},
|
|
208
185
|
)
|
|
209
|
-
if saved:
|
|
210
|
-
self._saved_state = state
|
|
211
|
-
else:
|
|
212
|
-
self._needs_save = True
|
|
213
|
-
|
|
214
|
-
async def _ensure_loaded(self) -> None:
|
|
215
|
-
# The lock makes a second caller wait for the stored data instead of
|
|
216
|
-
# working with the defaults and overwriting the file.
|
|
217
|
-
async with self._load_lock:
|
|
218
|
-
if self._needs_load:
|
|
219
|
-
await self._load_persists()
|
|
220
|
-
self._needs_load = False
|
|
221
186
|
|
|
222
187
|
# --- Public methods ---
|
|
223
188
|
|
|
@@ -230,11 +195,10 @@ class Action:
|
|
|
230
195
|
"""Store the travel time of a full drive in seconds, 0 means unknown."""
|
|
231
196
|
if not (math.isfinite(seconds) and seconds >= 0):
|
|
232
197
|
raise ValueError(f"Travel time must be a number >= 0: {seconds}")
|
|
233
|
-
await self._ensure_loaded()
|
|
234
198
|
self._settings = replace(
|
|
235
199
|
self._settings, **{f"travel_time_{direction.value}": float(seconds)}
|
|
236
200
|
)
|
|
237
|
-
await self.
|
|
201
|
+
await self.sync()
|
|
238
202
|
|
|
239
203
|
@property
|
|
240
204
|
def reported_rotation_range(self) -> tuple[Any, Any]:
|
|
@@ -254,19 +218,17 @@ class Action:
|
|
|
254
218
|
self, *, minimum: float | None = None, maximum: float | None = None
|
|
255
219
|
) -> None:
|
|
256
220
|
"""Overwrite one or both rotation limits and store them."""
|
|
257
|
-
await self._ensure_loaded()
|
|
258
221
|
if minimum is not None:
|
|
259
222
|
self._overwrites[_MIN_VALUE] = minimum
|
|
260
223
|
if maximum is not None:
|
|
261
224
|
self._overwrites[_MAX_VALUE] = maximum
|
|
262
|
-
await self.
|
|
225
|
+
await self.sync()
|
|
263
226
|
|
|
264
227
|
async def reset_rotation_range(self) -> None:
|
|
265
228
|
"""Remove the overwritten rotation limits and store that."""
|
|
266
|
-
await self._ensure_loaded()
|
|
267
229
|
self._overwrites.pop(_MIN_VALUE, None)
|
|
268
230
|
self._overwrites.pop(_MAX_VALUE, None)
|
|
269
|
-
await self.
|
|
231
|
+
await self.sync()
|
|
270
232
|
|
|
271
233
|
def rotation_to_tilt(self, rotation: float) -> int:
|
|
272
234
|
"""Convert a rotation to a tilt (0 closed, 100 open) with the limits in use."""
|
|
@@ -296,13 +258,12 @@ class Action:
|
|
|
296
258
|
return self.model.apply_measurement(now, position, tilt)
|
|
297
259
|
|
|
298
260
|
async def sync(self) -> None:
|
|
299
|
-
"""
|
|
261
|
+
"""Store changes of overwrites, settings and state.
|
|
300
262
|
|
|
301
263
|
Call this after commands and measurements. Destination.refresh does it too.
|
|
302
264
|
"""
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
await self._save_persists()
|
|
265
|
+
self._publish()
|
|
266
|
+
await self._store.flush()
|
|
306
267
|
|
|
307
268
|
def __getattr__(self, name: str) -> Any:
|
|
308
269
|
if name.startswith("_"):
|
|
@@ -323,14 +284,12 @@ class Action:
|
|
|
323
284
|
def __setitem__(self, name: str, value: Any) -> None:
|
|
324
285
|
if name in self._attrs:
|
|
325
286
|
self._overwrites[name] = value
|
|
326
|
-
self._needs_save = True
|
|
327
287
|
elif name in self._params:
|
|
328
288
|
self._params[name] = value
|
|
329
289
|
|
|
330
290
|
def __delitem__(self, name: str) -> None:
|
|
331
291
|
if name in self._overwrites:
|
|
332
292
|
del self._overwrites[name]
|
|
333
|
-
self._needs_save = True
|
|
334
293
|
|
|
335
294
|
def prep(self, **kwargs: Any) -> ActionList:
|
|
336
295
|
"""Return an action list with this action and the given parameters."""
|
|
@@ -46,10 +46,8 @@ class Destination:
|
|
|
46
46
|
**kwargs: Any,
|
|
47
47
|
) -> None:
|
|
48
48
|
self._control = control
|
|
49
|
-
# The id becomes part of a file path, so it must be a number.
|
|
50
49
|
self._id = int(id)
|
|
51
50
|
self._names = names
|
|
52
|
-
self._persist = (control._persist / str(self._id)) if control._persist else None
|
|
53
51
|
self._actions = {action["id"]: Action(self, **action) for action in actions}
|
|
54
52
|
self._animationType = WMS_WebControl_pro_API_animationType(animationType)
|
|
55
53
|
self._drivingCause = WMS_WebControl_pro_API_drivingCause.Unknown
|
|
@@ -135,9 +133,10 @@ class Destination:
|
|
|
135
133
|
# --- Public methods ---
|
|
136
134
|
|
|
137
135
|
async def sync(self) -> None:
|
|
138
|
-
"""
|
|
136
|
+
"""Store changes of all actions with one write for each file."""
|
|
139
137
|
for action in self._actions.values():
|
|
140
|
-
|
|
138
|
+
action._publish()
|
|
139
|
+
await self._control._store.flush()
|
|
141
140
|
|
|
142
141
|
async def refresh(
|
|
143
142
|
self, retries: int = DEFAULT_REFRESH_RETRIES, *, raise_on_error: bool = False
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Result and statistics of status requests to a destination."""
|
|
2
2
|
|
|
3
|
+
from collections.abc import Iterable
|
|
3
4
|
from dataclasses import dataclass, field, replace
|
|
4
5
|
from datetime import UTC, datetime
|
|
5
6
|
from enum import StrEnum
|
|
@@ -79,6 +80,25 @@ class RefreshStats:
|
|
|
79
80
|
return StaleChange.STALE
|
|
80
81
|
return None
|
|
81
82
|
|
|
83
|
+
@property
|
|
84
|
+
def success_rate(self) -> float | None:
|
|
85
|
+
"""Return the share of refreshes with data in percent, None without one."""
|
|
86
|
+
total = self.ok + self.busy + self.empty + self.error
|
|
87
|
+
return 100 * self.ok / total if total else None
|
|
88
|
+
|
|
89
|
+
@classmethod
|
|
90
|
+
def combined(cls, stats: Iterable[RefreshStats]) -> RefreshStats:
|
|
91
|
+
"""Return the sum of the counters and the latest refresh with data."""
|
|
92
|
+
total = cls()
|
|
93
|
+
for part in stats:
|
|
94
|
+
total.ok += part.ok
|
|
95
|
+
total.busy += part.busy
|
|
96
|
+
total.empty += part.empty
|
|
97
|
+
total.error += part.error
|
|
98
|
+
if part.last_ok and (total.last_ok is None or part.last_ok > total.last_ok):
|
|
99
|
+
total.last_ok = part.last_ok
|
|
100
|
+
return total
|
|
101
|
+
|
|
82
102
|
def snapshot(self) -> RefreshStats:
|
|
83
103
|
"""Return a copy that does not change with later refreshes."""
|
|
84
104
|
return replace(self)
|