pywmswebcontrolpro 0.9.0__tar.gz → 0.9.2__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.9.0 → pywmswebcontrolpro-0.9.2}/CHANGELOG.md +20 -1
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/PKG-INFO +1 -1
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/cover.py +31 -1
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/destination.py +8 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/travel.py +8 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/webcontrol.py +26 -10
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/conftest.py +18 -5
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_cover.py +29 -1
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/.github/workflows/release.yaml +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/.github/workflows/validate.yaml +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/.gitignore +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/.python-version +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/LICENSE +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/README.md +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/mypy.ini +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pyproject.toml +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pytest.ini +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/action.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/const.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/exceptions.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/py.typed +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/refresh.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/room.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/scene.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/store.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/requirements_lint.txt +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/requirements_test.txt +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/ruff.toml +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/simulator/simulator.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/__init__.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_client.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_configuration.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_import.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_refresh.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_rotation.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_settings.py +0 -0
- {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.2}/tests/test_travel.py +0 -0
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.9.
|
|
3
|
+
## 0.9.2 (unreleased)
|
|
4
|
+
|
|
5
|
+
Changed:
|
|
6
|
+
|
|
7
|
+
- The debug log shows a request when it is sent to the hub, not when it starts to wait
|
|
8
|
+
for the request before it, and the answer with its time. Until now a command that
|
|
9
|
+
waited for a running status request looked as if both went to the hub at once.
|
|
10
|
+
- A test checks that a command waits for a running status request: the library sends
|
|
11
|
+
one request at a time to a hub.
|
|
12
|
+
|
|
13
|
+
## 0.9.1
|
|
14
|
+
|
|
15
|
+
Added:
|
|
16
|
+
|
|
17
|
+
- Debug logs of every request to the hub and its answer, of each status with its
|
|
18
|
+
cause, and of the movement model after each command, measurement and end of a
|
|
19
|
+
movement. Enable the logger `pywmswebcontrolpro` at level debug to follow what the
|
|
20
|
+
hub reported and what the model made of it.
|
|
21
|
+
|
|
22
|
+
## 0.9.0
|
|
4
23
|
|
|
5
24
|
Added:
|
|
6
25
|
|
|
@@ -8,6 +8,7 @@ the one before.
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import asyncio
|
|
11
|
+
import logging
|
|
11
12
|
import math
|
|
12
13
|
from time import monotonic
|
|
13
14
|
from typing import TYPE_CHECKING, Any
|
|
@@ -23,6 +24,8 @@ from .travel import CoverModel, Measurement
|
|
|
23
24
|
if TYPE_CHECKING:
|
|
24
25
|
from .destination import Destination
|
|
25
26
|
|
|
27
|
+
_LOGGER = logging.getLogger(__name__)
|
|
28
|
+
|
|
26
29
|
|
|
27
30
|
class Cover:
|
|
28
31
|
"""A drive action of a destination and, for a slat drive, its rotation.
|
|
@@ -43,6 +46,10 @@ class Cover:
|
|
|
43
46
|
self._rotation = rotation
|
|
44
47
|
self._lock: asyncio.Lock = dest._command_lock
|
|
45
48
|
|
|
49
|
+
def __str__(self) -> str:
|
|
50
|
+
"""Return the destination and the drive for logs."""
|
|
51
|
+
return f"{self._dest} ({self._dest.id}) {self._drive}"
|
|
52
|
+
|
|
46
53
|
@property
|
|
47
54
|
def drive(self) -> Action:
|
|
48
55
|
"""Return the drive action."""
|
|
@@ -60,7 +67,10 @@ class Cover:
|
|
|
60
67
|
|
|
61
68
|
def advance(self) -> bool:
|
|
62
69
|
"""Move the displayed percentage to now, True if a drive ended with it."""
|
|
63
|
-
|
|
70
|
+
ended = self.model.advance(monotonic())
|
|
71
|
+
if ended:
|
|
72
|
+
_LOGGER.debug("%s: movement ended, %r", self, self.model)
|
|
73
|
+
return ended
|
|
64
74
|
|
|
65
75
|
async def apply_measurement(
|
|
66
76
|
self, percentage: float | None, rotation: int | None
|
|
@@ -71,6 +81,14 @@ class Cover:
|
|
|
71
81
|
measured one even when no command or status request follows.
|
|
72
82
|
"""
|
|
73
83
|
result = self._drive.apply_measurement(monotonic(), percentage, rotation)
|
|
84
|
+
_LOGGER.debug(
|
|
85
|
+
"%s: measured percentage %s, rotation %s, %s, %r",
|
|
86
|
+
self,
|
|
87
|
+
percentage,
|
|
88
|
+
rotation,
|
|
89
|
+
"applied" if result.applied else "ignored",
|
|
90
|
+
self.model,
|
|
91
|
+
)
|
|
74
92
|
await self._drive.sync()
|
|
75
93
|
return result
|
|
76
94
|
|
|
@@ -125,6 +143,7 @@ class Cover:
|
|
|
125
143
|
responseType=WMS_WebControl_pro_API_responseType.Detailed
|
|
126
144
|
)
|
|
127
145
|
delay = self.model.stop(monotonic())
|
|
146
|
+
_LOGGER.debug("%s: stopped, poll in %.1f s, %r", self, delay, self.model)
|
|
128
147
|
await self._drive.sync()
|
|
129
148
|
return delay
|
|
130
149
|
|
|
@@ -161,6 +180,14 @@ class Cover:
|
|
|
161
180
|
delay = self._drive.start_move(now, percentage, rotation, **self._slats())
|
|
162
181
|
if remember and rotation is not None:
|
|
163
182
|
self.model.remember_rotation(now, rotation)
|
|
183
|
+
_LOGGER.debug(
|
|
184
|
+
"%s: drive to %s with rotation %s, poll in %.1f s, %r",
|
|
185
|
+
self,
|
|
186
|
+
percentage,
|
|
187
|
+
rotation,
|
|
188
|
+
delay,
|
|
189
|
+
self.model,
|
|
190
|
+
)
|
|
164
191
|
await self._drive.sync()
|
|
165
192
|
return delay
|
|
166
193
|
|
|
@@ -173,6 +200,9 @@ class Cover:
|
|
|
173
200
|
now = monotonic()
|
|
174
201
|
delay = self.model.set_rotation(now, rotation, **self._slats())
|
|
175
202
|
self.model.remember_rotation(now, rotation)
|
|
203
|
+
_LOGGER.debug(
|
|
204
|
+
"%s: turn to %s, poll in %.1f s, %r", self, rotation, delay, self.model
|
|
205
|
+
)
|
|
176
206
|
await self._drive.sync()
|
|
177
207
|
return delay
|
|
178
208
|
|
|
@@ -162,6 +162,14 @@ class Destination:
|
|
|
162
162
|
await self.sync()
|
|
163
163
|
|
|
164
164
|
result, values, duration = await self._request_status(retries, raise_on_error)
|
|
165
|
+
_LOGGER.debug(
|
|
166
|
+
"Status of %s (%s), %s: %s %s",
|
|
167
|
+
self,
|
|
168
|
+
self._id,
|
|
169
|
+
cause.value,
|
|
170
|
+
result.value,
|
|
171
|
+
values,
|
|
172
|
+
)
|
|
165
173
|
self._record(result, cause, duration)
|
|
166
174
|
return RefreshOutcome(result, values)
|
|
167
175
|
|
|
@@ -166,6 +166,14 @@ class CoverModel:
|
|
|
166
166
|
self._drive_end: float | None = None
|
|
167
167
|
self._last_rotation: tuple[int, float] | None = None
|
|
168
168
|
|
|
169
|
+
def __repr__(self) -> str:
|
|
170
|
+
"""Return the state of the model for debug logs."""
|
|
171
|
+
return (
|
|
172
|
+
f"CoverModel(percentage={self.percentage!r}, rotation={self.rotation!r}, "
|
|
173
|
+
f"source={self.source!r}, motion={self._motion!r}, "
|
|
174
|
+
f"drive_target={self._drive_target!r}, drive_end={self._drive_end!r})"
|
|
175
|
+
)
|
|
176
|
+
|
|
169
177
|
# --- State ---
|
|
170
178
|
|
|
171
179
|
@property
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Client of the local API of the WMS WebControl pro gateway."""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import logging
|
|
4
5
|
import pprint
|
|
5
6
|
import time
|
|
6
7
|
from collections.abc import Mapping
|
|
@@ -41,6 +42,9 @@ DEFAULT_RETRY_DELAY = 1.0
|
|
|
41
42
|
DEFAULT_REQUEST_SPACING = 0.5
|
|
42
43
|
|
|
43
44
|
|
|
45
|
+
_LOGGER = logging.getLogger(__name__)
|
|
46
|
+
|
|
47
|
+
|
|
44
48
|
def _names(names: object) -> list[str]:
|
|
45
49
|
"""Return the names of a destination or raise ValueError."""
|
|
46
50
|
if not isinstance(names, list) or not names:
|
|
@@ -106,26 +110,38 @@ class WebControlPro:
|
|
|
106
110
|
"source": WMS_WebControl_pro_API_source,
|
|
107
111
|
}
|
|
108
112
|
data.update(kwargs)
|
|
113
|
+
# One request at a time per hub, a command waits for a running status
|
|
114
|
+
# request and the other way round.
|
|
115
|
+
async with self._common_lock:
|
|
116
|
+
_LOGGER.debug("Request to %s: %s", self._host, data)
|
|
117
|
+
started = time.monotonic()
|
|
118
|
+
answer = await self._post(command, data)
|
|
119
|
+
elapsed = time.monotonic() - started
|
|
120
|
+
if command == WMS_WebControl_pro_API_command_getConfiguration:
|
|
121
|
+
_LOGGER.debug("Answer to %s received", command)
|
|
122
|
+
else:
|
|
123
|
+
_LOGGER.debug("Answer to %s after %.2f s: %s", command, elapsed, answer)
|
|
124
|
+
if not isinstance(answer, dict):
|
|
125
|
+
raise WebControlProResponseError(f"Unexpected answer to {command}")
|
|
126
|
+
return answer
|
|
127
|
+
|
|
128
|
+
async def _post(self, command: str, data: dict[str, Any]) -> Any:
|
|
109
129
|
try:
|
|
110
|
-
async with (
|
|
111
|
-
self.
|
|
112
|
-
|
|
113
|
-
url=self._control, json=data, timeout=ClientTimeout(total=5)
|
|
114
|
-
) as response,
|
|
115
|
-
):
|
|
130
|
+
async with self._session.post(
|
|
131
|
+
url=self._control, json=data, timeout=ClientTimeout(total=5)
|
|
132
|
+
) as response:
|
|
116
133
|
response.raise_for_status()
|
|
117
|
-
|
|
134
|
+
return await response.json()
|
|
118
135
|
except (ClientResponseError, ValueError) as err:
|
|
136
|
+
_LOGGER.debug("Unexpected answer to %s: %r", command, err)
|
|
119
137
|
raise WebControlProResponseError(
|
|
120
138
|
f"Unexpected answer to {command}: {err!r}"
|
|
121
139
|
) from err
|
|
122
140
|
except (ClientError, TimeoutError) as err:
|
|
141
|
+
_LOGGER.debug("No answer to %s: %r", command, err)
|
|
123
142
|
raise WebControlProConnectionError(
|
|
124
143
|
f"No answer to {command}: {err!r}"
|
|
125
144
|
) from err
|
|
126
|
-
if not isinstance(answer, dict):
|
|
127
|
-
raise WebControlProResponseError(f"Unexpected answer to {command}")
|
|
128
|
-
return answer
|
|
129
145
|
|
|
130
146
|
async def _command(self, command: str, **kwargs: Any) -> Any:
|
|
131
147
|
answer = await self._commonCommand(command, **kwargs)
|
|
@@ -109,11 +109,19 @@ class BadBody:
|
|
|
109
109
|
class FakeRequest:
|
|
110
110
|
"""Async context manager returned by the fake session."""
|
|
111
111
|
|
|
112
|
-
def __init__(
|
|
112
|
+
def __init__(
|
|
113
|
+
self, answer: Any, delay: float = 0, gateway: FakeGateway | None = None
|
|
114
|
+
) -> None:
|
|
113
115
|
self._answer = answer
|
|
114
116
|
self._delay = delay
|
|
117
|
+
self._gateway = gateway
|
|
115
118
|
|
|
116
119
|
async def __aenter__(self) -> FakeResponse:
|
|
120
|
+
if self._gateway is not None:
|
|
121
|
+
self._gateway.in_flight += 1
|
|
122
|
+
self._gateway.most_in_flight = max(
|
|
123
|
+
self._gateway.most_in_flight, self._gateway.in_flight
|
|
124
|
+
)
|
|
117
125
|
if self._delay:
|
|
118
126
|
await asyncio.sleep(self._delay)
|
|
119
127
|
if isinstance(self._answer, Exception):
|
|
@@ -128,7 +136,8 @@ class FakeRequest:
|
|
|
128
136
|
exc: BaseException | None,
|
|
129
137
|
tb: TracebackType | None,
|
|
130
138
|
) -> None:
|
|
131
|
-
|
|
139
|
+
if self._gateway is not None:
|
|
140
|
+
self._gateway.in_flight -= 1
|
|
132
141
|
|
|
133
142
|
|
|
134
143
|
class FakeGateway:
|
|
@@ -139,8 +148,12 @@ class FakeGateway:
|
|
|
139
148
|
self.requests: list[dict[str, Any]] = []
|
|
140
149
|
self.config: Any = CONFIG
|
|
141
150
|
self.command_answer: Any = {"status": 0}
|
|
142
|
-
# Seconds the gateway takes to answer a command.
|
|
151
|
+
# Seconds the gateway takes to answer a command or a status request.
|
|
143
152
|
self.command_delay = 0.0
|
|
153
|
+
self.status_delay = 0.0
|
|
154
|
+
# Requests the gateway works on at the same time, and the most of them.
|
|
155
|
+
self.in_flight = 0
|
|
156
|
+
self.most_in_flight = 0
|
|
144
157
|
|
|
145
158
|
def post(self, url: str, json: dict[str, Any], timeout: int) -> FakeRequest:
|
|
146
159
|
"""Answer one request of the library."""
|
|
@@ -148,8 +161,8 @@ class FakeGateway:
|
|
|
148
161
|
if json["command"] == "getConfiguration":
|
|
149
162
|
return FakeRequest(self.config)
|
|
150
163
|
if json["command"] == "getStatus":
|
|
151
|
-
return FakeRequest(self.status_answers.pop(0))
|
|
152
|
-
return FakeRequest(self.command_answer, self.command_delay)
|
|
164
|
+
return FakeRequest(self.status_answers.pop(0), self.status_delay, self)
|
|
165
|
+
return FakeRequest(self.command_answer, self.command_delay, self)
|
|
153
166
|
|
|
154
167
|
@property
|
|
155
168
|
def status_requests(self) -> int:
|
|
@@ -17,7 +17,7 @@ from pywmswebcontrolpro.refresh import ERROR_RADIO_BUSY
|
|
|
17
17
|
from pywmswebcontrolpro.store import TravelDirection
|
|
18
18
|
from pywmswebcontrolpro.webcontrol import WebControlPro
|
|
19
19
|
|
|
20
|
-
from .conftest import DEST_ID, FakeGateway, stored_state
|
|
20
|
+
from .conftest import DEST_ID, STATUS_BUSY, FakeGateway, stored_state
|
|
21
21
|
|
|
22
22
|
type ControlFactory = Callable[..., WebControlPro]
|
|
23
23
|
|
|
@@ -503,3 +503,31 @@ async def test_rotation_alone_waits_for_the_turn(
|
|
|
503
503
|
clock.at(0.9)
|
|
504
504
|
assert cover.advance() is True
|
|
505
505
|
assert cover.model.rotation == 0
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
async def test_commands_and_measurements_are_logged(
|
|
509
|
+
cover: Cover, clock: Clock, caplog: pytest.LogCaptureFixture
|
|
510
|
+
) -> None:
|
|
511
|
+
caplog.set_level("DEBUG", logger="pywmswebcontrolpro")
|
|
512
|
+
|
|
513
|
+
await cover.move(40)
|
|
514
|
+
clock.at(30)
|
|
515
|
+
await cover.apply_measurement(42, 15)
|
|
516
|
+
|
|
517
|
+
messages = [record.getMessage() for record in caplog.records]
|
|
518
|
+
assert any(m.startswith("Request to ") and "'action'" in m for m in messages)
|
|
519
|
+
assert any("Blind (9) " in m and "drive to 40 with rotation" in m for m in messages)
|
|
520
|
+
assert any("measured percentage 42, rotation 15, applied" in m for m in messages)
|
|
521
|
+
assert any(m.startswith("Answer to action after ") for m in messages)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
async def test_command_waits_for_a_running_status_request(
|
|
525
|
+
cover: Cover, control: WebControlPro, gateway: FakeGateway
|
|
526
|
+
) -> None:
|
|
527
|
+
gateway.status_delay = gateway.command_delay = 0.01
|
|
528
|
+
gateway.status_answers = [STATUS_BUSY]
|
|
529
|
+
|
|
530
|
+
await asyncio.gather(control.dests[DEST_ID].refresh(), cover.set_rotation(-37))
|
|
531
|
+
|
|
532
|
+
assert gateway.most_in_flight == 1
|
|
533
|
+
assert [r["command"] for r in gateway.requests[-2:]] == ["getStatus", "action"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|