pywmswebcontrolpro 0.1.2__tar.gz → 0.2.1__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.1.2 → pywmswebcontrolpro-0.2.1}/.github/workflows/release.yaml +4 -3
- pywmswebcontrolpro-0.2.1/CHANGELOG.md +66 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/PKG-INFO +51 -5
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/README.md +49 -4
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/mypy.ini +1 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pyproject.toml +3 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/action.py +138 -21
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/const.py +13 -4
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/destination.py +32 -16
- pywmswebcontrolpro-0.2.1/pywmswebcontrolpro/exceptions.py +24 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/room.py +7 -4
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/scene.py +4 -2
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/store.py +44 -13
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/travel.py +33 -2
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/webcontrol.py +82 -28
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/conftest.py +24 -7
- pywmswebcontrolpro-0.2.1/tests/test_client.py +277 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/test_configuration.py +37 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/test_refresh.py +19 -5
- pywmswebcontrolpro-0.2.1/tests/test_rotation.py +212 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/test_settings.py +96 -2
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/test_travel.py +18 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/.gitignore +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/.python-version +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/LICENSE +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.1.2 → pywmswebcontrolpro-0.2.1}/tests/test_import.py +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: Release
|
|
3
|
-
on:
|
|
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:
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1 (unreleased)
|
|
4
|
+
|
|
5
|
+
Changed:
|
|
6
|
+
|
|
7
|
+
- A measured tilt without a position is taken over by the movement model
|
|
8
|
+
(`Measurement.applied` is true). Before, the whole measurement was dropped.
|
|
9
|
+
- `WebControlPro.refresh()` takes over changed names of known destinations and names
|
|
10
|
+
them in `ConfigChanges.renamed`.
|
|
11
|
+
- Packages are only built and uploaded to TestPyPI and PyPI for a tag, no longer for
|
|
12
|
+
every push.
|
|
13
|
+
|
|
14
|
+
## 0.2.0
|
|
15
|
+
|
|
16
|
+
Breaking changes:
|
|
17
|
+
|
|
18
|
+
- Requests raise the errors of the library (`WebControlProConnectionError`,
|
|
19
|
+
`WebControlProResponseError`) instead of `aiohttp.ClientError` and `TimeoutError`.
|
|
20
|
+
- An action or a scene that the gateway rejects raises `WebControlProCommandError`
|
|
21
|
+
instead of returning the answer with its `errors`.
|
|
22
|
+
- `Destination.refresh()` does not ask again by default when the radio is busy
|
|
23
|
+
(`retries=0`, was 2).
|
|
24
|
+
- A rotation action whose limits the hub reports as -127 and 127 uses -75 and 75
|
|
25
|
+
(`minValue`, `maxValue`, `rotation_range`). `wms__minValue`, `wms__maxValue` and
|
|
26
|
+
`reported_rotation_range` return the limits of the hub.
|
|
27
|
+
- Actions of different destinations with the same id are no longer equal.
|
|
28
|
+
|
|
29
|
+
Added:
|
|
30
|
+
|
|
31
|
+
- Workaround for the firmware bug of the rotation limits in the library: default
|
|
32
|
+
limits, learning from a larger measured rotation, `Action.set_rotation_range`,
|
|
33
|
+
`Action.reset_rotation_range`, `Action.rotation_to_tilt` and
|
|
34
|
+
`Action.tilt_to_rotation`. The conversion is linear and sends whole numbers within
|
|
35
|
+
the limits.
|
|
36
|
+
- Unknown enumeration values of a newer firmware become `Unknown`, unknown fields of
|
|
37
|
+
the configuration are ignored.
|
|
38
|
+
|
|
39
|
+
Fixed:
|
|
40
|
+
|
|
41
|
+
- The HTTP status of an answer is checked, an answer that is no JSON object is an
|
|
42
|
+
error of the library.
|
|
43
|
+
- A configuration that is not understood leaves the known destinations unchanged.
|
|
44
|
+
- A status with an error other than radio busy counts as `error` instead of `empty`
|
|
45
|
+
and does not replace the last status.
|
|
46
|
+
- A change during the first load of the stored file no longer replaces the file with
|
|
47
|
+
defaults. A change during a write is stored with the next sync.
|
|
48
|
+
- The stored file is written through a temporary file of its own and synced to disk.
|
|
49
|
+
A failed write is logged and tried again, a file with a broken encoding or an
|
|
50
|
+
invalid stored position is ignored.
|
|
51
|
+
- Ids of destinations and actions must be numbers, they are part of a file path.
|
|
52
|
+
|
|
53
|
+
## 0.1.2
|
|
54
|
+
|
|
55
|
+
- Keep known destinations when the configuration is read again.
|
|
56
|
+
|
|
57
|
+
## 0.1.1
|
|
58
|
+
|
|
59
|
+
- Docstrings, type hints and `py.typed`.
|
|
60
|
+
|
|
61
|
+
## 0.1.0
|
|
62
|
+
|
|
63
|
+
- First release as `pywmswebcontrolpro`, forked from `pywmspro` by Marc Hoersken.
|
|
64
|
+
- Refresh outcome and counters per destination, settings, movement model and stored
|
|
65
|
+
state per drive action.
|
|
66
|
+
- The spacing of status requests is a constructor argument.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pywmswebcontrolpro
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Python library for the Warema WMS WebControl pro API
|
|
5
5
|
Author-email: Marc Hoersken <info@marc-hoersken.de>
|
|
6
|
+
Maintainer: zomtec
|
|
6
7
|
License-Expression: Apache-2.0
|
|
7
8
|
License-File: LICENSE
|
|
8
9
|
Keywords: warema,webcontrol,wms
|
|
@@ -32,11 +33,11 @@ See the main section in `pywmswebcontrolpro/webcontrol.py`.
|
|
|
32
33
|
|
|
33
34
|
## Status refresh
|
|
34
35
|
|
|
35
|
-
`Destination.refresh(
|
|
36
|
+
`Destination.refresh()` requests the status of a destination once and returns a
|
|
36
37
|
`RefreshOutcome` with the result (`ok`, `busy`, `empty` or `error`) and the values
|
|
37
|
-
of the actions.
|
|
38
|
-
|
|
39
|
-
truthy only for `ok`.
|
|
38
|
+
of the actions. A "radio busy" answer is not retried by default, because every request
|
|
39
|
+
adds traffic to the radio channel; `retries=2` asks up to two more times. On any
|
|
40
|
+
failure the previous values stay unchanged. The outcome is truthy only for `ok`.
|
|
40
41
|
|
|
41
42
|
`WebControlPro(request_spacing=...)` sets the minimum pause between two status requests
|
|
42
43
|
to the hub (default 0.5 seconds).
|
|
@@ -46,6 +47,29 @@ Failed refreshes are counted per destination (`Destination.stats`, also part of
|
|
|
46
47
|
failed continuously for `stale_warning_after` (default 24 hours) and once when it
|
|
47
48
|
delivers data again.
|
|
48
49
|
|
|
50
|
+
## Errors
|
|
51
|
+
|
|
52
|
+
All errors of the library derive from `WebControlProError`
|
|
53
|
+
(`pywmswebcontrolpro.exceptions`):
|
|
54
|
+
|
|
55
|
+
- `WebControlProConnectionError`: the gateway did not answer (connection error or
|
|
56
|
+
timeout of 5 seconds).
|
|
57
|
+
- `WebControlProResponseError`: the gateway answered with an HTTP error or with
|
|
58
|
+
something that is not understood. A configuration that is not understood leaves the
|
|
59
|
+
known destinations unchanged.
|
|
60
|
+
- `WebControlProCommandError`: the gateway rejected an action or a scene, for example
|
|
61
|
+
because the radio channel is busy. `errors` holds the codes of the gateway. A
|
|
62
|
+
rejected command is not sent again.
|
|
63
|
+
|
|
64
|
+
`Destination.refresh()` raises none of them unless `raise_on_error=True` is passed, it
|
|
65
|
+
reports them as result `error`. Fields and enumeration values that a newer firmware
|
|
66
|
+
adds are accepted, an unknown value becomes `Unknown`.
|
|
67
|
+
|
|
68
|
+
## Security
|
|
69
|
+
|
|
70
|
+
The gateway offers its API only over HTTP without authentication, so the library
|
|
71
|
+
cannot encrypt or authenticate the connection. Run the gateway in a trusted network.
|
|
72
|
+
|
|
49
73
|
## Settings, movement model and stored state
|
|
50
74
|
|
|
51
75
|
Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
|
|
@@ -68,6 +92,28 @@ independently. After a restart the position is restored from the file and marked
|
|
|
68
92
|
`restored` until a measurement arrives. Call `Action.sync()` after commands and
|
|
69
93
|
measurements to store changes; `Destination.refresh` does it as well.
|
|
70
94
|
|
|
95
|
+
## Rotation limits of slat drives (firmware bug)
|
|
96
|
+
|
|
97
|
+
The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
|
|
98
|
+
from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
|
|
99
|
+
(rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
|
|
100
|
+
not been announced.
|
|
101
|
+
|
|
102
|
+
The library works around it in `pywmswebcontrolpro/action.py`:
|
|
103
|
+
|
|
104
|
+
- While the hub reports exactly -127 and 127 for a rotation action, `Action.rotation_range`
|
|
105
|
+
is -75 to 75. `Action.reported_rotation_range` returns the limits of the hub.
|
|
106
|
+
- A rotation that is measured beyond the range in use widens it. The limits of the hub
|
|
107
|
+
themselves (-127 and 127) are never learned.
|
|
108
|
+
- `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.
|
|
110
|
+
- `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
|
|
111
|
+
use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
|
|
112
|
+
rotation that is sent is a whole number within the limits.
|
|
113
|
+
|
|
114
|
+
The workaround ends by itself when a firmware reports other limits. It can be removed
|
|
115
|
+
from the library once such a firmware is available.
|
|
116
|
+
|
|
71
117
|
## Development
|
|
72
118
|
|
|
73
119
|
```bash
|
|
@@ -19,11 +19,11 @@ See the main section in `pywmswebcontrolpro/webcontrol.py`.
|
|
|
19
19
|
|
|
20
20
|
## Status refresh
|
|
21
21
|
|
|
22
|
-
`Destination.refresh(
|
|
22
|
+
`Destination.refresh()` requests the status of a destination once and returns a
|
|
23
23
|
`RefreshOutcome` with the result (`ok`, `busy`, `empty` or `error`) and the values
|
|
24
|
-
of the actions.
|
|
25
|
-
|
|
26
|
-
truthy only for `ok`.
|
|
24
|
+
of the actions. A "radio busy" answer is not retried by default, because every request
|
|
25
|
+
adds traffic to the radio channel; `retries=2` asks up to two more times. On any
|
|
26
|
+
failure the previous values stay unchanged. The outcome is truthy only for `ok`.
|
|
27
27
|
|
|
28
28
|
`WebControlPro(request_spacing=...)` sets the minimum pause between two status requests
|
|
29
29
|
to the hub (default 0.5 seconds).
|
|
@@ -33,6 +33,29 @@ Failed refreshes are counted per destination (`Destination.stats`, also part of
|
|
|
33
33
|
failed continuously for `stale_warning_after` (default 24 hours) and once when it
|
|
34
34
|
delivers data again.
|
|
35
35
|
|
|
36
|
+
## Errors
|
|
37
|
+
|
|
38
|
+
All errors of the library derive from `WebControlProError`
|
|
39
|
+
(`pywmswebcontrolpro.exceptions`):
|
|
40
|
+
|
|
41
|
+
- `WebControlProConnectionError`: the gateway did not answer (connection error or
|
|
42
|
+
timeout of 5 seconds).
|
|
43
|
+
- `WebControlProResponseError`: the gateway answered with an HTTP error or with
|
|
44
|
+
something that is not understood. A configuration that is not understood leaves the
|
|
45
|
+
known destinations unchanged.
|
|
46
|
+
- `WebControlProCommandError`: the gateway rejected an action or a scene, for example
|
|
47
|
+
because the radio channel is busy. `errors` holds the codes of the gateway. A
|
|
48
|
+
rejected command is not sent again.
|
|
49
|
+
|
|
50
|
+
`Destination.refresh()` raises none of them unless `raise_on_error=True` is passed, it
|
|
51
|
+
reports them as result `error`. Fields and enumeration values that a newer firmware
|
|
52
|
+
adds are accepted, an unknown value becomes `Unknown`.
|
|
53
|
+
|
|
54
|
+
## Security
|
|
55
|
+
|
|
56
|
+
The gateway offers its API only over HTTP without authentication, so the library
|
|
57
|
+
cannot encrypt or authenticate the connection. Run the gateway in a trusted network.
|
|
58
|
+
|
|
36
59
|
## Settings, movement model and stored state
|
|
37
60
|
|
|
38
61
|
Each action keeps its data in `<persist>/<destination id>/<action id>.json`, the file
|
|
@@ -55,6 +78,28 @@ independently. After a restart the position is restored from the file and marked
|
|
|
55
78
|
`restored` until a measurement arrives. Call `Action.sync()` after commands and
|
|
56
79
|
measurements to store changes; `Destination.refresh` does it as well.
|
|
57
80
|
|
|
81
|
+
## Rotation limits of slat drives (firmware bug)
|
|
82
|
+
|
|
83
|
+
The hub reports the rotation limits of slat drives as -127 and 127. The drives turn
|
|
84
|
+
from -75 to 75, so a tilt calculated from the reported limits is wrong: closed slats
|
|
85
|
+
(rotation 75) would be shown as 21 % open. Warema knows the bug, a fixed firmware has
|
|
86
|
+
not been announced.
|
|
87
|
+
|
|
88
|
+
The library works around it in `pywmswebcontrolpro/action.py`:
|
|
89
|
+
|
|
90
|
+
- While the hub reports exactly -127 and 127 for a rotation action, `Action.rotation_range`
|
|
91
|
+
is -75 to 75. `Action.reported_rotation_range` returns the limits of the hub.
|
|
92
|
+
- A rotation that is measured beyond the range in use widens it. The limits of the hub
|
|
93
|
+
themselves (-127 and 127) are never learned.
|
|
94
|
+
- `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.
|
|
96
|
+
- `Action.rotation_to_tilt` and `Action.tilt_to_rotation` convert with the limits in
|
|
97
|
+
use. The minimum rotation is tilt 100, the maximum rotation is tilt 0, and the
|
|
98
|
+
rotation that is sent is a whole number within the limits.
|
|
99
|
+
|
|
100
|
+
The workaround ends by itself when a firmware reports other limits. It can be removed
|
|
101
|
+
from the library once such a firmware is available.
|
|
102
|
+
|
|
58
103
|
## Development
|
|
59
104
|
|
|
60
105
|
```bash
|
|
@@ -7,6 +7,9 @@ license-files = ["LICENSE"]
|
|
|
7
7
|
authors = [
|
|
8
8
|
{ name = "Marc Hoersken", email = "info@marc-hoersken.de" }
|
|
9
9
|
]
|
|
10
|
+
maintainers = [
|
|
11
|
+
{ name = "zomtec" }
|
|
12
|
+
]
|
|
10
13
|
readme = "README.md"
|
|
11
14
|
repository = "https://github.com/zomtec/pywmswebcontrolpro"
|
|
12
15
|
keywords = ["warema", "wms", "webcontrol"]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""An action of a destination with its stored settings and movement model."""
|
|
2
2
|
|
|
3
|
+
import asyncio
|
|
3
4
|
import math
|
|
4
5
|
from dataclasses import asdict, replace
|
|
5
6
|
from typing import TYPE_CHECKING, Any
|
|
@@ -9,8 +10,14 @@ from .const import (
|
|
|
9
10
|
WMS_WebControl_pro_API_actionType,
|
|
10
11
|
WMS_WebControl_pro_API_responseType,
|
|
11
12
|
)
|
|
12
|
-
from .store import
|
|
13
|
-
|
|
13
|
+
from .store import (
|
|
14
|
+
STORE_VERSION,
|
|
15
|
+
ActionSettings,
|
|
16
|
+
JsonStore,
|
|
17
|
+
TravelDirection,
|
|
18
|
+
valid_percent,
|
|
19
|
+
)
|
|
20
|
+
from .travel import CoverModel, Measurement, rotation_to_tilt, tilt_to_rotation
|
|
14
21
|
|
|
15
22
|
if TYPE_CHECKING:
|
|
16
23
|
from .destination import Destination
|
|
@@ -18,8 +25,23 @@ if TYPE_CHECKING:
|
|
|
18
25
|
|
|
19
26
|
_STORED_KEYS = frozenset({"version", "overwrites", "settings", "state"})
|
|
20
27
|
|
|
28
|
+
# Firmware bug of the WMS WebControl pro: the hub reports the rotation limits
|
|
29
|
+
# of slat drives as -127 and 127, the drives turn from -75 to 75. Warema knows
|
|
30
|
+
# the bug and has not fixed it. While the hub reports exactly these limits,
|
|
31
|
+
# -75 and 75 are used instead. A rotation measured beyond them widens the
|
|
32
|
+
# range, and the user can overwrite it. The workaround ends by itself when a
|
|
33
|
+
# firmware reports other limits and can then be removed.
|
|
34
|
+
ROTATION_LIMIT_REPORTED_BY_BUG = 127
|
|
35
|
+
ROTATION_LIMIT_DEFAULT = 75
|
|
36
|
+
_MIN_VALUE = "minValue"
|
|
37
|
+
_MAX_VALUE = "maxValue"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _is_number(value: Any) -> bool:
|
|
41
|
+
return isinstance(value, int | float) and not isinstance(value, bool)
|
|
42
|
+
|
|
21
43
|
|
|
22
|
-
class ActionList(list):
|
|
44
|
+
class ActionList(list[dict[str, Any]]):
|
|
23
45
|
"""Actions that are sent to the gateway with one request."""
|
|
24
46
|
|
|
25
47
|
def __init__(self, control: WebControlPro) -> None:
|
|
@@ -55,17 +77,20 @@ class Action:
|
|
|
55
77
|
) -> None:
|
|
56
78
|
"""Create the action from the configuration of the gateway."""
|
|
57
79
|
self._dest = dest
|
|
58
|
-
|
|
59
|
-
self.
|
|
80
|
+
# The id becomes part of a file path, so it must be a number.
|
|
81
|
+
self._id = int(id)
|
|
82
|
+
self._persist = (dest._persist / f"{self._id}.json") if dest._persist else None
|
|
60
83
|
self._store = JsonStore(self._persist)
|
|
61
84
|
self._actionType = WMS_WebControl_pro_API_actionType(actionType)
|
|
62
85
|
self._actionDescription = WMS_WebControl_pro_API_actionDescription(
|
|
63
86
|
actionDescription
|
|
64
87
|
)
|
|
65
88
|
self._attrs = kwargs
|
|
89
|
+
self._defaults = self._rotation_defaults()
|
|
66
90
|
self._params: dict[str, Any] = {}
|
|
67
91
|
self._overwrites: dict[str, Any] = {}
|
|
68
92
|
self._needs_load = True
|
|
93
|
+
self._load_lock = asyncio.Lock()
|
|
69
94
|
self._needs_save = False
|
|
70
95
|
self._extra: dict[str, Any] = {}
|
|
71
96
|
self._settings = ActionSettings()
|
|
@@ -79,10 +104,14 @@ class Action:
|
|
|
79
104
|
return f"<Action {self.id}: {self} ({self.actionType.name})>"
|
|
80
105
|
|
|
81
106
|
def __eq__(self, other: object) -> bool:
|
|
82
|
-
return
|
|
107
|
+
return (
|
|
108
|
+
isinstance(other, Action)
|
|
109
|
+
and self._dest == other._dest
|
|
110
|
+
and self.id == other.id
|
|
111
|
+
)
|
|
83
112
|
|
|
84
113
|
def __hash__(self) -> int:
|
|
85
|
-
return hash(self.id)
|
|
114
|
+
return hash((self._dest.id, self.id))
|
|
86
115
|
|
|
87
116
|
# --- Properties ---
|
|
88
117
|
|
|
@@ -108,8 +137,41 @@ class Action:
|
|
|
108
137
|
|
|
109
138
|
# --- Private methods ---
|
|
110
139
|
|
|
111
|
-
def
|
|
140
|
+
def _rotation_defaults(self) -> dict[str, Any]:
|
|
141
|
+
if (
|
|
142
|
+
self._actionType is WMS_WebControl_pro_API_actionType.Rotation
|
|
143
|
+
and self._attrs.get(_MIN_VALUE) == -ROTATION_LIMIT_REPORTED_BY_BUG
|
|
144
|
+
and self._attrs.get(_MAX_VALUE) == ROTATION_LIMIT_REPORTED_BY_BUG
|
|
145
|
+
):
|
|
146
|
+
return {
|
|
147
|
+
_MIN_VALUE: -ROTATION_LIMIT_DEFAULT,
|
|
148
|
+
_MAX_VALUE: ROTATION_LIMIT_DEFAULT,
|
|
149
|
+
}
|
|
150
|
+
return {}
|
|
151
|
+
|
|
152
|
+
def _update_params(self, value: dict[str, Any]) -> None:
|
|
112
153
|
self._params.update(value)
|
|
154
|
+
self._learn_rotation_range(value.get("rotation"))
|
|
155
|
+
|
|
156
|
+
def _learn_rotation_range(self, rotation: Any) -> None:
|
|
157
|
+
if (
|
|
158
|
+
self._actionType is not WMS_WebControl_pro_API_actionType.Rotation
|
|
159
|
+
or not _is_number(rotation)
|
|
160
|
+
):
|
|
161
|
+
return
|
|
162
|
+
reported_min, reported_max = self.reported_rotation_range
|
|
163
|
+
if not (_is_number(reported_min) and _is_number(reported_max)):
|
|
164
|
+
return
|
|
165
|
+
# The reported limits themselves are no real position of a drive.
|
|
166
|
+
if not reported_min < rotation < reported_max:
|
|
167
|
+
return
|
|
168
|
+
minimum, maximum = self.rotation_range
|
|
169
|
+
if rotation < minimum:
|
|
170
|
+
self._overwrites[_MIN_VALUE] = rotation
|
|
171
|
+
self._needs_save = True
|
|
172
|
+
elif rotation > maximum:
|
|
173
|
+
self._overwrites[_MAX_VALUE] = rotation
|
|
174
|
+
self._needs_save = True
|
|
113
175
|
|
|
114
176
|
async def _load_persists(self) -> None:
|
|
115
177
|
data = await self._store.load()
|
|
@@ -120,17 +182,22 @@ class Action:
|
|
|
120
182
|
self._settings = ActionSettings.from_dict(data.get("settings"))
|
|
121
183
|
state = data.get("state")
|
|
122
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"))
|
|
123
188
|
self.model.restore(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
state.get("target_position"),
|
|
127
|
-
|
|
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),
|
|
128
193
|
)
|
|
129
194
|
self._saved_state = self.model.snapshot()
|
|
130
195
|
|
|
131
196
|
async def _save_persists(self) -> None:
|
|
132
197
|
state = self.model.snapshot()
|
|
133
|
-
|
|
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(
|
|
134
201
|
{
|
|
135
202
|
**self._extra,
|
|
136
203
|
"version": STORE_VERSION,
|
|
@@ -139,13 +206,18 @@ class Action:
|
|
|
139
206
|
"state": state,
|
|
140
207
|
}
|
|
141
208
|
)
|
|
142
|
-
|
|
143
|
-
|
|
209
|
+
if saved:
|
|
210
|
+
self._saved_state = state
|
|
211
|
+
else:
|
|
212
|
+
self._needs_save = True
|
|
144
213
|
|
|
145
214
|
async def _ensure_loaded(self) -> None:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
149
221
|
|
|
150
222
|
# --- Public methods ---
|
|
151
223
|
|
|
@@ -164,6 +236,46 @@ class Action:
|
|
|
164
236
|
)
|
|
165
237
|
await self._save_persists()
|
|
166
238
|
|
|
239
|
+
@property
|
|
240
|
+
def reported_rotation_range(self) -> tuple[Any, Any]:
|
|
241
|
+
"""Return the rotation limits as the hub reports them."""
|
|
242
|
+
return self._attrs.get(_MIN_VALUE), self._attrs.get(_MAX_VALUE)
|
|
243
|
+
|
|
244
|
+
@property
|
|
245
|
+
def rotation_range(self) -> tuple[float, float]:
|
|
246
|
+
"""Return the rotation limits in use, minimum and maximum.
|
|
247
|
+
|
|
248
|
+
An overwrite wins over the default for the firmware bug, which wins
|
|
249
|
+
over the limits of the hub.
|
|
250
|
+
"""
|
|
251
|
+
return self.minValue, self.maxValue
|
|
252
|
+
|
|
253
|
+
async def set_rotation_range(
|
|
254
|
+
self, *, minimum: float | None = None, maximum: float | None = None
|
|
255
|
+
) -> None:
|
|
256
|
+
"""Overwrite one or both rotation limits and store them."""
|
|
257
|
+
await self._ensure_loaded()
|
|
258
|
+
if minimum is not None:
|
|
259
|
+
self._overwrites[_MIN_VALUE] = minimum
|
|
260
|
+
if maximum is not None:
|
|
261
|
+
self._overwrites[_MAX_VALUE] = maximum
|
|
262
|
+
await self._save_persists()
|
|
263
|
+
|
|
264
|
+
async def reset_rotation_range(self) -> None:
|
|
265
|
+
"""Remove the overwritten rotation limits and store that."""
|
|
266
|
+
await self._ensure_loaded()
|
|
267
|
+
self._overwrites.pop(_MIN_VALUE, None)
|
|
268
|
+
self._overwrites.pop(_MAX_VALUE, None)
|
|
269
|
+
await self._save_persists()
|
|
270
|
+
|
|
271
|
+
def rotation_to_tilt(self, rotation: float) -> int:
|
|
272
|
+
"""Convert a rotation to a tilt (0 closed, 100 open) with the limits in use."""
|
|
273
|
+
return rotation_to_tilt(rotation, *self.rotation_range)
|
|
274
|
+
|
|
275
|
+
def tilt_to_rotation(self, tilt: float) -> int:
|
|
276
|
+
"""Convert a tilt (0 closed, 100 open) to a rotation with the limits in use."""
|
|
277
|
+
return tilt_to_rotation(tilt, *self.rotation_range)
|
|
278
|
+
|
|
167
279
|
def start_move(self, now: float, target: float, tilt: int | None = None) -> float:
|
|
168
280
|
"""Handle an accepted drive command with the stored travel times.
|
|
169
281
|
|
|
@@ -180,7 +292,7 @@ class Action:
|
|
|
180
292
|
def apply_measurement(
|
|
181
293
|
self, now: float, position: int | None, tilt: int | None
|
|
182
294
|
) -> Measurement:
|
|
183
|
-
"""Take over a measured position unless a drive is running."""
|
|
295
|
+
"""Take over a measured position or tilt unless a drive is running."""
|
|
184
296
|
return self.model.apply_measurement(now, position, tilt)
|
|
185
297
|
|
|
186
298
|
async def sync(self) -> None:
|
|
@@ -193,10 +305,14 @@ class Action:
|
|
|
193
305
|
await self._save_persists()
|
|
194
306
|
|
|
195
307
|
def __getattr__(self, name: str) -> Any:
|
|
308
|
+
if name.startswith("_"):
|
|
309
|
+
raise AttributeError(name)
|
|
196
310
|
if name in self._overwrites:
|
|
197
311
|
return self._overwrites[name]
|
|
198
312
|
if name.startswith("wms__"):
|
|
199
|
-
|
|
313
|
+
return self._attrs.get(name[5:])
|
|
314
|
+
if name in self._defaults:
|
|
315
|
+
return self._defaults[name]
|
|
200
316
|
return self._attrs.get(name)
|
|
201
317
|
|
|
202
318
|
def __getitem__(self, name: str) -> Any:
|
|
@@ -241,7 +357,7 @@ class Action:
|
|
|
241
357
|
responseType=responseType,
|
|
242
358
|
)
|
|
243
359
|
|
|
244
|
-
def diag(self) -> dict:
|
|
360
|
+
def diag(self) -> dict[str, Any]:
|
|
245
361
|
"""Return the action for the diagnostics."""
|
|
246
362
|
return {
|
|
247
363
|
"id": self.id,
|
|
@@ -250,6 +366,7 @@ class Action:
|
|
|
250
366
|
"attrs": self._attrs,
|
|
251
367
|
"params": self._params,
|
|
252
368
|
"overwrites": self._overwrites,
|
|
369
|
+
"defaults": self._defaults,
|
|
253
370
|
"settings": asdict(self._settings),
|
|
254
371
|
"model": {
|
|
255
372
|
**self.model.snapshot(),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Constants and enumerations of the WMS WebControl pro API."""
|
|
2
2
|
|
|
3
3
|
from enum import IntEnum
|
|
4
|
+
from typing import Self
|
|
4
5
|
|
|
5
6
|
WMS_WebControl_pro_API_protocolVersion = "1.0"
|
|
6
7
|
WMS_WebControl_pro_API_source = 2
|
|
@@ -12,7 +13,15 @@ WMS_WebControl_pro_API_command_action = "action"
|
|
|
12
13
|
WMS_WebControl_pro_API_command_sceneActions = "sceneActions"
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
class
|
|
16
|
+
class _TolerantIntEnum(IntEnum):
|
|
17
|
+
"""Enumeration that maps a value of a newer firmware to Unknown."""
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def _missing_(cls, value: object) -> Self:
|
|
21
|
+
return cls["Unknown"]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class WMS_WebControl_pro_API_animationType(_TolerantIntEnum):
|
|
16
25
|
"""Kind of device that a destination controls."""
|
|
17
26
|
|
|
18
27
|
VenetianBlind = 0
|
|
@@ -25,7 +34,7 @@ class WMS_WebControl_pro_API_animationType(IntEnum):
|
|
|
25
34
|
Unknown = 999
|
|
26
35
|
|
|
27
36
|
|
|
28
|
-
class WMS_WebControl_pro_API_actionType(
|
|
37
|
+
class WMS_WebControl_pro_API_actionType(_TolerantIntEnum):
|
|
29
38
|
"""Kind of value or command of an action."""
|
|
30
39
|
|
|
31
40
|
Percentage = 0
|
|
@@ -41,7 +50,7 @@ class WMS_WebControl_pro_API_actionType(IntEnum):
|
|
|
41
50
|
Unknown = 999
|
|
42
51
|
|
|
43
52
|
|
|
44
|
-
class WMS_WebControl_pro_API_actionDescription(
|
|
53
|
+
class WMS_WebControl_pro_API_actionDescription(_TolerantIntEnum):
|
|
45
54
|
"""Function of an action, for example awning drive or light switch."""
|
|
46
55
|
|
|
47
56
|
AwningDrive = 0
|
|
@@ -75,7 +84,7 @@ class WMS_WebControl_pro_API_sceneActionType(IntEnum):
|
|
|
75
84
|
Execute = 1
|
|
76
85
|
|
|
77
86
|
|
|
78
|
-
class WMS_WebControl_pro_API_drivingCause(
|
|
87
|
+
class WMS_WebControl_pro_API_drivingCause(_TolerantIntEnum):
|
|
79
88
|
"""Reason why a drive moved last."""
|
|
80
89
|
|
|
81
90
|
_None = 0 # No driving cause
|