pywmswebcontrolpro 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/.github/workflows/release.yaml +4 -3
  2. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/CHANGELOG.md +38 -1
  3. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/PKG-INFO +29 -14
  4. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/README.md +28 -13
  5. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/action.py +39 -80
  6. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/destination.py +9 -4
  7. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/refresh.py +20 -0
  8. pywmswebcontrolpro-0.3.0/pywmswebcontrolpro/store.py +224 -0
  9. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/travel.py +11 -2
  10. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/webcontrol.py +39 -9
  11. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/conftest.py +13 -0
  12. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_configuration.py +37 -0
  13. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_refresh.py +42 -0
  14. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_rotation.py +5 -5
  15. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_settings.py +202 -87
  16. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_travel.py +18 -0
  17. pywmswebcontrolpro-0.2.0/pywmswebcontrolpro/store.py +0 -135
  18. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/.github/workflows/validate.yaml +0 -0
  19. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/.gitignore +0 -0
  20. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/.python-version +0 -0
  21. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/LICENSE +0 -0
  22. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/mypy.ini +0 -0
  23. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pyproject.toml +0 -0
  24. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pytest.ini +0 -0
  25. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/__init__.py +0 -0
  26. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/const.py +0 -0
  27. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/exceptions.py +0 -0
  28. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/py.typed +0 -0
  29. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/room.py +0 -0
  30. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/pywmswebcontrolpro/scene.py +0 -0
  31. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/requirements_lint.txt +0 -0
  32. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/requirements_test.txt +0 -0
  33. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/ruff.toml +0 -0
  34. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/simulator/simulator.py +0 -0
  35. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/__init__.py +0 -0
  36. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_client.py +0 -0
  37. {pywmswebcontrolpro-0.2.0 → pywmswebcontrolpro-0.3.0}/tests/test_import.py +0 -0
@@ -1,6 +1,9 @@
1
1
  ---
2
2
  name: Release
3
- on: [ push ]
3
+ on:
4
+ push:
5
+ tags:
6
+ - "*"
4
7
  jobs:
5
8
  build:
6
9
  runs-on: ubuntu-latest
@@ -33,7 +36,6 @@ jobs:
33
36
  skip-existing: true
34
37
  print-hash: true
35
38
  github-release:
36
- if: github.ref_type == 'tag'
37
39
  runs-on: ubuntu-latest
38
40
  needs: test-pypi
39
41
  permissions:
@@ -60,7 +62,6 @@ jobs:
60
62
  env:
61
63
  GH_TOKEN: "${{ github.token }}"
62
64
  prod-pypi:
63
- if: github.ref_type == 'tag'
64
65
  runs-on: ubuntu-latest
65
66
  needs: github-release
66
67
  environment:
@@ -1,6 +1,43 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.0 (unreleased)
3
+ ## 0.3.0 (unreleased)
4
+
5
+ Breaking changes:
6
+
7
+ - The stored data of all actions of a hub is kept in two files of the persist
8
+ directory, `settings.json` (travel times and overwrites) and `state.json` (last known
9
+ position and tilt), instead of one file for each action
10
+ (`<destination id>/<action id>.json`). The old files are not read and not removed,
11
+ travel times and changed rotation limits have to be set again.
12
+ - `JsonStore` is replaced by `HubStore`, the store of a client that reads the files
13
+ once and is the only place that writes them.
14
+
15
+ Added:
16
+
17
+ - `RefreshStats.success_rate`, the share of refreshes with data in percent, and
18
+ `WebControlPro.stats`, the counters of all destinations together.
19
+
20
+ Changed:
21
+
22
+ - Only data that differs from the defaults is stored, an action without travel times,
23
+ overwrites or a known position has no entry.
24
+ - A drive writes only `state.json`, the settings are written when they change.
25
+ - Changes of several actions of a destination are stored with one write for each file.
26
+ - An action has its stored data as soon as `WebControlPro.refresh()` created it, no
27
+ longer after the first `sync()`.
28
+
29
+ ## 0.2.1
30
+
31
+ Changed:
32
+
33
+ - A measured tilt without a position is taken over by the movement model
34
+ (`Measurement.applied` is true). Before, the whole measurement was dropped.
35
+ - `WebControlPro.refresh()` takes over changed names of known destinations and names
36
+ them in `ConfigChanges.renamed`.
37
+ - Packages are only built and uploaded to TestPyPI and PyPI for a tag, no longer for
38
+ every push.
39
+
40
+ ## 0.2.0
4
41
 
5
42
  Breaking changes:
6
43
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pywmswebcontrolpro
3
- Version: 0.2.0
3
+ Version: 0.3.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. A warning is logged once when a destination has
47
- failed continuously for `stale_warning_after` (default 24 hours) and once when it
48
- delivers data again.
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,30 @@ 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
- Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
76
- that already holds the `overwrites` (for example the rotation limits). A drive action
77
- (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) stores in it:
77
+ The client keeps the data of all actions of a hub in two files of the `persist`
78
+ directory:
78
79
 
79
- - `settings`: the travel times for a full drive, open and close, in seconds
80
- (`Action.set_travel_time`, 0 means unknown).
81
- - `state`: the last known position and tilt and the target of a running drive.
80
+ - `settings.json`: what was set or learned and cannot be measured again. For a drive
81
+ action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
82
+ are the travel times for a full drive, open and close, in seconds
83
+ (`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
84
+ of the rotation limits.
85
+ - `state.json`: the last known position and tilt of a drive action and the target of a
86
+ running drive.
82
87
 
83
- The file is written atomically and serialized against concurrent access, unknown keys
84
- and the `overwrites` of older versions are kept. Without a persist path nothing is
85
- stored.
88
+ Both files have an entry for each destination and action, and only for data that
89
+ differs from the defaults:
90
+
91
+ ```json
92
+ {"version": 1, "destinations": {"169520": {"0": {"settings": {"travel_time_open": 39.0, "travel_time_close": 39.0}}, "6": {"overwrites": {"minValue": -70}}}}}
93
+ ```
94
+
95
+ The store of the client (`pywmswebcontrolpro/store.py`) is the only place that reads
96
+ and writes the files. It reads them once with the first `WebControlPro.refresh()`, an
97
+ action has its stored data from then on. Writes are serialized and replace a file
98
+ atomically, changes that arrive during a write are stored together with the next one.
99
+ A drive only writes `state.json`. Entries of destinations that the hub does not report
100
+ are kept. Without a persist path nothing is stored.
86
101
 
87
102
  `Action.model` is the movement model of the cover driven by this action: `start_move`,
88
103
  `stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
@@ -106,7 +121,7 @@ The library works around it in `pywmswebcontrolpro/action.py`:
106
121
  - A rotation that is measured beyond the range in use widens it. The limits of the hub
107
122
  themselves (-127 and 127) are never learned.
108
123
  - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
109
- returns to the default. Both are stored in the file of the action.
124
+ returns to the default. Both are stored in `settings.json`.
110
125
  - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
111
126
  use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
112
127
  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. A warning is logged once when a destination has
33
- failed continuously for `stale_warning_after` (default 24 hours) and once when it
34
- delivers data again.
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,30 @@ 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
- Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
62
- that already holds the `overwrites` (for example the rotation limits). A drive action
63
- (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) stores in it:
63
+ The client keeps the data of all actions of a hub in two files of the `persist`
64
+ directory:
64
65
 
65
- - `settings`: the travel times for a full drive, open and close, in seconds
66
- (`Action.set_travel_time`, 0 means unknown).
67
- - `state`: the last known position and tilt and the target of a running drive.
66
+ - `settings.json`: what was set or learned and cannot be measured again. For a drive
67
+ action (for example `AwningDrive`, `ValanceDrive` or `RollerShutterBlindDrive`) these
68
+ are the travel times for a full drive, open and close, in seconds
69
+ (`Action.set_travel_time`, 0 means unknown), for a rotation action the `overwrites`
70
+ of the rotation limits.
71
+ - `state.json`: the last known position and tilt of a drive action and the target of a
72
+ running drive.
68
73
 
69
- The file is written atomically and serialized against concurrent access, unknown keys
70
- and the `overwrites` of older versions are kept. Without a persist path nothing is
71
- stored.
74
+ Both files have an entry for each destination and action, and only for data that
75
+ differs from the defaults:
76
+
77
+ ```json
78
+ {"version": 1, "destinations": {"169520": {"0": {"settings": {"travel_time_open": 39.0, "travel_time_close": 39.0}}, "6": {"overwrites": {"minValue": -70}}}}}
79
+ ```
80
+
81
+ The store of the client (`pywmswebcontrolpro/store.py`) is the only place that reads
82
+ and writes the files. It reads them once with the first `WebControlPro.refresh()`, an
83
+ action has its stored data from then on. Writes are serialized and replace a file
84
+ atomically, changes that arrive during a write are stored together with the next one.
85
+ A drive only writes `state.json`. Entries of destinations that the hub does not report
86
+ are kept. Without a persist path nothing is stored.
72
87
 
73
88
  `Action.model` is the movement model of the cover driven by this action: `start_move`,
74
89
  `stop`, `set_tilt` and `apply_measurement` calculate the displayed position, which is
@@ -92,7 +107,7 @@ The library works around it in `pywmswebcontrolpro/action.py`:
92
107
  - A rotation that is measured beyond the range in use widens it. The limits of the hub
93
108
  themselves (-127 and 127) are never learned.
94
109
  - `Action.set_rotation_range` overwrites the limits, `Action.reset_rotation_range`
95
- returns to the default. Both are stored in the file of the action.
110
+ returns to the default. Both are stored in `settings.json`.
96
111
  - `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
97
112
  use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
98
113
  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._persist = (dest._persist / f"{self._id}.json") if dest._persist else None
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._overwrites: dict[str, Any] = {}
92
- self._needs_load = True
93
- self._load_lock = asyncio.Lock()
94
- self._needs_save = False
95
- self._extra: dict[str, Any] = {}
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
- self._needs_save = True
175
-
176
- async def _load_persists(self) -> None:
177
- data = await self._store.load()
178
- self._extra = {k: v for k, v in data.items() if k not in _STORED_KEYS}
179
- overwrites = data.get("overwrites")
180
- if isinstance(overwrites, dict):
181
- self._overwrites = overwrites
182
- self._settings = ActionSettings.from_dict(data.get("settings"))
183
- state = data.get("state")
184
- if isinstance(state, dict):
185
- position = valid_percent(state.get("position"))
186
- tilt = valid_percent(state.get("tilt"))
187
- target_tilt = valid_percent(state.get("target_tilt"))
188
- self.model.restore(
189
- position,
190
- None if tilt is None else int(tilt),
191
- valid_percent(state.get("target_position")),
192
- None if target_tilt is None else int(target_tilt),
193
- )
194
- self._saved_state = self.model.snapshot()
195
-
196
- async def _save_persists(self) -> None:
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._save_persists()
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._save_persists()
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._save_persists()
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."""
@@ -292,17 +254,16 @@ class Action:
292
254
  def apply_measurement(
293
255
  self, now: float, position: int | None, tilt: int | None
294
256
  ) -> Measurement:
295
- """Take over a measured position unless a drive is running."""
257
+ """Take over a measured position or tilt unless a drive is running."""
296
258
  return self.model.apply_measurement(now, position, tilt)
297
259
 
298
260
  async def sync(self) -> None:
299
- """Load stored data once and store changes of overwrites, settings and state.
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
- await self._ensure_loaded()
304
- if self._needs_save or self.model.snapshot() != self._saved_state:
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
@@ -88,6 +86,12 @@ class Destination:
88
86
  """Return the name of the destination."""
89
87
  return self._names[0]
90
88
 
89
+ def _rename(self, names: list[str]) -> bool:
90
+ """Take over the names of the configuration, True if the name changed."""
91
+ changed = names[0] != self.name
92
+ self._names = names
93
+ return changed
94
+
91
95
  @property
92
96
  def actions(self) -> dict[int, Action]:
93
97
  """Return the actions of the destination by id."""
@@ -129,9 +133,10 @@ class Destination:
129
133
  # --- Public methods ---
130
134
 
131
135
  async def sync(self) -> None:
132
- """Load stored data once and store changes of all actions."""
136
+ """Store changes of all actions with one write for each file."""
133
137
  for action in self._actions.values():
134
- await action.sync()
138
+ action._publish()
139
+ await self._control._store.flush()
135
140
 
136
141
  async def refresh(
137
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)