pywmswebcontrolpro 0.9.0__tar.gz → 0.9.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.
Files changed (38) hide show
  1. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/CHANGELOG.md +10 -1
  2. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/PKG-INFO +1 -1
  3. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/cover.py +31 -1
  4. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/destination.py +8 -0
  5. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/travel.py +8 -0
  6. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/webcontrol.py +11 -0
  7. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_cover.py +16 -0
  8. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/.github/workflows/release.yaml +0 -0
  9. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/.github/workflows/validate.yaml +0 -0
  10. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/.gitignore +0 -0
  11. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/.python-version +0 -0
  12. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/LICENSE +0 -0
  13. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/README.md +0 -0
  14. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/mypy.ini +0 -0
  15. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pyproject.toml +0 -0
  16. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pytest.ini +0 -0
  17. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/__init__.py +0 -0
  18. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/action.py +0 -0
  19. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/const.py +0 -0
  20. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/exceptions.py +0 -0
  21. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/py.typed +0 -0
  22. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/refresh.py +0 -0
  23. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/room.py +0 -0
  24. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/scene.py +0 -0
  25. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/pywmswebcontrolpro/store.py +0 -0
  26. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/requirements_lint.txt +0 -0
  27. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/requirements_test.txt +0 -0
  28. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/ruff.toml +0 -0
  29. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/simulator/simulator.py +0 -0
  30. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/__init__.py +0 -0
  31. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/conftest.py +0 -0
  32. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_client.py +0 -0
  33. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_configuration.py +0 -0
  34. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_import.py +0 -0
  35. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_refresh.py +0 -0
  36. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_rotation.py +0 -0
  37. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_settings.py +0 -0
  38. {pywmswebcontrolpro-0.9.0 → pywmswebcontrolpro-0.9.1}/tests/test_travel.py +0 -0
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ## 0.9.0 (unreleased)
3
+ ## 0.9.1 (unreleased)
4
+
5
+ Added:
6
+
7
+ - Debug logs of every request to the hub and its answer, of each status with its
8
+ cause, and of the movement model after each command, measurement and end of a
9
+ movement. Enable the logger `pywmswebcontrolpro` at level debug to follow what the
10
+ hub reported and what the model made of it.
11
+
12
+ ## 0.9.0
4
13
 
5
14
  Added:
6
15
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pywmswebcontrolpro
3
- Version: 0.9.0
3
+ Version: 0.9.1
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
@@ -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
- return self.model.advance(monotonic())
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,6 +110,7 @@ class WebControlPro:
106
110
  "source": WMS_WebControl_pro_API_source,
107
111
  }
108
112
  data.update(kwargs)
113
+ _LOGGER.debug("Request to %s: %s", self._host, data)
109
114
  try:
110
115
  async with (
111
116
  self._common_lock,
@@ -116,13 +121,19 @@ class WebControlPro:
116
121
  response.raise_for_status()
117
122
  answer = await response.json()
118
123
  except (ClientResponseError, ValueError) as err:
124
+ _LOGGER.debug("Unexpected answer to %s: %r", command, err)
119
125
  raise WebControlProResponseError(
120
126
  f"Unexpected answer to {command}: {err!r}"
121
127
  ) from err
122
128
  except (ClientError, TimeoutError) as err:
129
+ _LOGGER.debug("No answer to %s: %r", command, err)
123
130
  raise WebControlProConnectionError(
124
131
  f"No answer to {command}: {err!r}"
125
132
  ) 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)
126
137
  if not isinstance(answer, dict):
127
138
  raise WebControlProResponseError(f"Unexpected answer to {command}")
128
139
  return answer
@@ -503,3 +503,19 @@ 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("Answer to action: " in m for m in messages)