pywmswebcontrolpro 0.9.1__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.
Files changed (38) hide show
  1. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/CHANGELOG.md +11 -1
  2. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/PKG-INFO +1 -1
  3. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/webcontrol.py +20 -15
  4. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/conftest.py +18 -5
  5. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_cover.py +14 -2
  6. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/.github/workflows/release.yaml +0 -0
  7. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/.github/workflows/validate.yaml +0 -0
  8. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/.gitignore +0 -0
  9. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/.python-version +0 -0
  10. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/LICENSE +0 -0
  11. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/README.md +0 -0
  12. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/mypy.ini +0 -0
  13. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pyproject.toml +0 -0
  14. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pytest.ini +0 -0
  15. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/__init__.py +0 -0
  16. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/action.py +0 -0
  17. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/const.py +0 -0
  18. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/cover.py +0 -0
  19. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/destination.py +0 -0
  20. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/exceptions.py +0 -0
  21. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/py.typed +0 -0
  22. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/refresh.py +0 -0
  23. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/room.py +0 -0
  24. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/scene.py +0 -0
  25. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/store.py +0 -0
  26. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/pywmswebcontrolpro/travel.py +0 -0
  27. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/requirements_lint.txt +0 -0
  28. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/requirements_test.txt +0 -0
  29. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/ruff.toml +0 -0
  30. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/simulator/simulator.py +0 -0
  31. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/__init__.py +0 -0
  32. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_client.py +0 -0
  33. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_configuration.py +0 -0
  34. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_import.py +0 -0
  35. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_refresh.py +0 -0
  36. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_rotation.py +0 -0
  37. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_settings.py +0 -0
  38. {pywmswebcontrolpro-0.9.1 → pywmswebcontrolpro-0.9.2}/tests/test_travel.py +0 -0
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## 0.9.1 (unreleased)
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
4
14
 
5
15
  Added:
6
16
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pywmswebcontrolpro
3
- Version: 0.9.1
3
+ Version: 0.9.2
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
@@ -110,16 +110,28 @@ class WebControlPro:
110
110
  "source": WMS_WebControl_pro_API_source,
111
111
  }
112
112
  data.update(kwargs)
113
- _LOGGER.debug("Request to %s: %s", self._host, data)
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:
114
129
  try:
115
- async with (
116
- self._common_lock,
117
- self._session.post(
118
- url=self._control, json=data, timeout=ClientTimeout(total=5)
119
- ) as response,
120
- ):
130
+ async with self._session.post(
131
+ url=self._control, json=data, timeout=ClientTimeout(total=5)
132
+ ) as response:
121
133
  response.raise_for_status()
122
- answer = await response.json()
134
+ return await response.json()
123
135
  except (ClientResponseError, ValueError) as err:
124
136
  _LOGGER.debug("Unexpected answer to %s: %r", command, err)
125
137
  raise WebControlProResponseError(
@@ -130,13 +142,6 @@ class WebControlPro:
130
142
  raise WebControlProConnectionError(
131
143
  f"No answer to {command}: {err!r}"
132
144
  ) from err
133
- if command == WMS_WebControl_pro_API_command_getConfiguration:
134
- _LOGGER.debug("Answer to %s received", command)
135
- else:
136
- _LOGGER.debug("Answer to %s: %s", command, answer)
137
- if not isinstance(answer, dict):
138
- raise WebControlProResponseError(f"Unexpected answer to {command}")
139
- return answer
140
145
 
141
146
  async def _command(self, command: str, **kwargs: Any) -> Any:
142
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__(self, answer: Any, delay: float = 0) -> None:
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
- return None
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
 
@@ -518,4 +518,16 @@ async def test_commands_and_measurements_are_logged(
518
518
  assert any(m.startswith("Request to ") and "'action'" in m for m in messages)
519
519
  assert any("Blind (9) " in m and "drive to 40 with rotation" in m for m in messages)
520
520
  assert any("measured percentage 42, rotation 15, applied" in m for m in messages)
521
- assert any("Answer to action: " 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"]