pywiim 3.0.2__tar.gz → 3.0.4__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 (88) hide show
  1. {pywiim-3.0.2/pywiim.egg-info → pywiim-3.0.4}/PKG-INFO +1 -1
  2. {pywiim-3.0.2 → pywiim-3.0.4}/pyproject.toml +1 -1
  3. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/__init__.py +16 -1
  4. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/audio_settings.py +18 -2
  5. pywiim-3.0.4/pywiim/api/ble_remote.py +243 -0
  6. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/constants.py +11 -0
  7. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/capabilities.py +39 -2
  8. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/diagnostics.py +40 -0
  9. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/client.py +3 -0
  10. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/__init__.py +115 -2
  11. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/audio.py +17 -6
  12. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/base.py +9 -0
  13. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/diagnostics.py +10 -0
  14. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/properties.py +15 -0
  15. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/statemgr.py +36 -3
  16. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/polling.py +24 -0
  17. {pywiim-3.0.2 → pywiim-3.0.4/pywiim.egg-info}/PKG-INFO +1 -1
  18. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim.egg-info/SOURCES.txt +3 -1
  19. pywiim-3.0.4/tests/test_release_preflight.py +115 -0
  20. {pywiim-3.0.2 → pywiim-3.0.4}/LICENSE +0 -0
  21. {pywiim-3.0.2 → pywiim-3.0.4}/README.md +0 -0
  22. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/__init__.py +0 -0
  23. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/audio_pro.py +0 -0
  24. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/base.py +0 -0
  25. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/bluetooth.py +0 -0
  26. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/device.py +0 -0
  27. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/diagnostics.py +0 -0
  28. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/endpoints.py +0 -0
  29. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/eq.py +0 -0
  30. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/firmware.py +0 -0
  31. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/group.py +0 -0
  32. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/lms.py +0 -0
  33. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/loop_mode.py +0 -0
  34. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/misc.py +0 -0
  35. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/parser.py +0 -0
  36. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/peq.py +0 -0
  37. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/playback.py +0 -0
  38. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/preset.py +0 -0
  39. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/ssl.py +0 -0
  40. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/subwoofer.py +0 -0
  41. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/api/timer.py +0 -0
  42. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/backoff.py +0 -0
  43. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/__init__.py +0 -0
  44. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/discovery_cli.py +0 -0
  45. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/group_test_cli.py +0 -0
  46. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/join_test_cli.py +0 -0
  47. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/monitor_cli.py +0 -0
  48. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/cli/verify_cli.py +0 -0
  49. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/device_capabilities.py +0 -0
  50. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/discovery.py +0 -0
  51. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/exceptions.py +0 -0
  52. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/group.py +0 -0
  53. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/group_helpers.py +0 -0
  54. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/__init__.py +0 -0
  55. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/__main__.py +0 -0
  56. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/config.example.json +0 -0
  57. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/config.py +0 -0
  58. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/context.py +0 -0
  59. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/mcp/server.py +0 -0
  60. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/metadata.py +0 -0
  61. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/model_names.py +0 -0
  62. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/models.py +0 -0
  63. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/normalize.py +0 -0
  64. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/bluetooth.py +0 -0
  65. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/coverart.py +0 -0
  66. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/debounce.py +0 -0
  67. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/groupops.py +0 -0
  68. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/media.py +0 -0
  69. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/playback.py +0 -0
  70. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/source_capabilities.py +0 -0
  71. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/stream.py +0 -0
  72. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/stream_enricher.py +0 -0
  73. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/player/volume.py +0 -0
  74. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/profiles.py +0 -0
  75. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/py.typed +0 -0
  76. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/role.py +0 -0
  77. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/state.py +0 -0
  78. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/__init__.py +0 -0
  79. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/client.py +0 -0
  80. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/eventer.py +0 -0
  81. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/health.py +0 -0
  82. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/metadata.py +0 -0
  83. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim/upnp/playqueue.py +0 -0
  84. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim.egg-info/dependency_links.txt +0 -0
  85. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim.egg-info/entry_points.txt +0 -0
  86. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim.egg-info/requires.txt +0 -0
  87. {pywiim-3.0.2 → pywiim-3.0.4}/pywiim.egg-info/top_level.txt +0 -0
  88. {pywiim-3.0.2 → pywiim-3.0.4}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywiim
3
- Version: 3.0.2
3
+ Version: 3.0.4
4
4
  Summary: Python library for WiiM/LinkPlay device communication
5
5
  Author-email: Michael Cumming <mjcumming@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pywiim"
7
- version = "3.0.2"
7
+ version = "3.0.4"
8
8
  description = "Python library for WiiM/LinkPlay device communication"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -20,6 +20,14 @@ Example:
20
20
 
21
21
  from __future__ import annotations
22
22
 
23
+ from .api.ble_remote import (
24
+ REMOTE_VOLUME_STEP_DEFAULT,
25
+ REMOTE_VOLUME_STEP_MAX,
26
+ REMOTE_VOLUME_STEP_MIN,
27
+ REMOTE_VOLUME_STEPS,
28
+ BleRemoteIdentity,
29
+ BleRemoteState,
30
+ )
23
31
  from .api.constants import (
24
32
  ALARM_OP_PLAYBACK,
25
33
  ALARM_OP_SHELL,
@@ -105,7 +113,7 @@ from .profiles import (
105
113
  from .role import RoleDetectionResult, detect_role
106
114
  from .state import GroupStateSynchronizer, StateSynchronizer
107
115
 
108
- __version__ = "3.0.2"
116
+ __version__ = "3.0.4"
109
117
  __all__ = [
110
118
  # Main client
111
119
  "WiiMClient",
@@ -171,6 +179,13 @@ __all__ = [
171
179
  "ALARM_OP_SHELL",
172
180
  "ALARM_OP_PLAYBACK",
173
181
  "ALARM_OP_STOP",
182
+ # WiiM Voice Remote
183
+ "BleRemoteState",
184
+ "BleRemoteIdentity",
185
+ "REMOTE_VOLUME_STEPS",
186
+ "REMOTE_VOLUME_STEP_MIN",
187
+ "REMOTE_VOLUME_STEP_MAX",
188
+ "REMOTE_VOLUME_STEP_DEFAULT",
174
189
  # Subwoofer (WiiM Ultra)
175
190
  "SubwooferStatus",
176
191
  "SUBWOOFER_CROSSOVER_MIN",
@@ -25,6 +25,7 @@ from .constants import (
25
25
  API_ENDPOINT_SET_CHANNEL_MODE,
26
26
  API_ENDPOINT_SET_OUTPUT_CHANNEL,
27
27
  API_ENDPOINT_SET_SPDIF_SWITCH_DELAY,
28
+ CHANNEL_MODE_MAP,
28
29
  OUTPUT_CHANNEL_MAP,
29
30
  )
30
31
 
@@ -44,6 +45,21 @@ def output_channel_value(channel: str) -> int:
44
45
  raise ValueError(f"Output channel must be one of {list(OUTPUT_CHANNEL_MAP.values())}, got {channel!r}")
45
46
 
46
47
 
48
+ def channel_mode_value(channel: str) -> int:
49
+ """Return the standalone channel-mode wire value (0-3) for a name.
50
+
51
+ Accepts ``stereo`` / ``left`` / ``right`` / ``mono``, ignoring case and surrounding spaces.
52
+
53
+ Raises:
54
+ ValueError: If ``channel`` is not one of the four names.
55
+ """
56
+ wanted = channel.strip().lower() if isinstance(channel, str) else ""
57
+ for value, name in CHANNEL_MODE_MAP.items():
58
+ if name == wanted:
59
+ return value
60
+ raise ValueError(f"Channel mode must be one of {list(CHANNEL_MODE_MAP.values())}, got {channel!r}")
61
+
62
+
47
63
  class AudioSettingsAPI:
48
64
  """Audio settings helpers (SPDIF, balance, etc.).
49
65
 
@@ -210,8 +226,8 @@ class AudioSettingsAPI:
210
226
  return mode
211
227
 
212
228
  async def set_channel_mode(self, channel: str) -> None:
213
- """Set standalone playback to stereo, left or right."""
214
- value = output_channel_value(channel)
229
+ """Set standalone playback to stereo, left, right or mono."""
230
+ value = channel_mode_value(channel)
215
231
  endpoint = f"{API_ENDPOINT_SET_CHANNEL_MODE}{value}"
216
232
  response = await self._request(endpoint) # type: ignore[attr-defined]
217
233
  if (response.raw or "").strip().upper() != "OK" and response.parsed != "OK":
@@ -0,0 +1,243 @@
1
+ """WiiM Voice Remote (Bluetooth LE) API.
2
+
3
+ Read-only status plus the remote's volume step setting. Verified on a WiiM Pro Plus
4
+ (firmware Linkplay.4.8.833841); other models and firmware are not tested.
5
+
6
+ Sources (see ADR 025):
7
+ - ``getStatusEx`` ``BleRemoteControl`` is ``"1"`` whenever the speaker supports a remote, paired or
8
+ not. That flag is read from the device info already fetched at connect. The regular poll does
9
+ not call ``getStatusEx`` again for the remote (ADR 024).
10
+ - ``getblehidstatus`` is the remote read: connected, battery, RSSI, name, MAC, and firmware.
11
+ Battery can lag after a battery change. While the remote is not connected, battery and RSSI
12
+ are reported as None.
13
+ - ``get_remote_volume_step`` / ``set_remote_volume_step:N`` (N = 1-5) read and write the setting.
14
+
15
+ This module never builds the commands that pair, remove or update the remote. The BLE MAC is
16
+ kept out of ``repr`` and masked in diagnostics.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import logging
22
+ from collections.abc import Mapping
23
+ from dataclasses import dataclass, field
24
+ from types import MappingProxyType
25
+ from typing import Any
26
+
27
+ from ..exceptions import WiiMError
28
+ from .constants import (
29
+ API_ENDPOINT_BLE_REMOTE_STATUS,
30
+ API_ENDPOINT_REMOTE_VOLUME_STEP_GET,
31
+ API_ENDPOINT_REMOTE_VOLUME_STEP_SET,
32
+ )
33
+
34
+ _LOGGER = logging.getLogger(__name__)
35
+
36
+ REMOTE_VOLUME_STEP_MIN = 1
37
+ REMOTE_VOLUME_STEP_MAX = 5
38
+ REMOTE_VOLUME_STEP_DEFAULT = 1
39
+
40
+ # Labels as shown in the WiiM Home app (English). Integrations may translate them.
41
+ REMOTE_VOLUME_STEPS: Mapping[int, str] = MappingProxyType(
42
+ {
43
+ 1: "Fine Adjustment",
44
+ 2: "Small Step",
45
+ 3: "Medium Step",
46
+ 4: "Large Step",
47
+ 5: "Quick Adjustment",
48
+ }
49
+ )
50
+
51
+ _UNPAIRED_MAC = "00:00:00:00:00:00"
52
+
53
+
54
+ def mask_mac(mac: str | None) -> str | None:
55
+ """Return *mac* with every octet masked, or None when there is no MAC."""
56
+ if not mac:
57
+ return None
58
+ return ":".join("XX" for _ in mac.split(":"))
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class BleRemoteIdentity:
63
+ """What ``getblehidstatus`` says about the remote (slow-changing).
64
+
65
+ Attributes:
66
+ status: Raw status string (``connected``, ``notconnect``, ``scanning``; others pass through).
67
+ paired: True when a remote is stored (non-empty name and a non-zero MAC).
68
+ name: Remote name, or None when not paired.
69
+ mac: Remote BLE MAC, or None when not paired. Hidden from ``repr``.
70
+ firmware: Remote firmware string such as ``"0054"``, or None.
71
+ battery: Battery percent from this response. It can lag after a battery change.
72
+ rssi: Signal strength in dBm from this response, including a stale value while disconnected.
73
+ """
74
+
75
+ status: str
76
+ paired: bool
77
+ name: str | None
78
+ mac: str | None = field(repr=False)
79
+ firmware: str | None
80
+ battery: int | None
81
+ rssi: int | None
82
+
83
+
84
+ @dataclass(frozen=True)
85
+ class BleRemoteState:
86
+ """Typed state of the WiiM Voice Remote.
87
+
88
+ Attributes:
89
+ paired: True/False from ``getblehidstatus``; None until that has been read.
90
+ connected: Whether the remote is currently connected.
91
+ name: Remote name, None when not paired or not read yet.
92
+ mac: Remote BLE MAC, None when not paired or not read yet. Hidden from ``repr``;
93
+ masked by :meth:`diagnostics_dict`.
94
+ firmware: Remote firmware string (for example ``"0054"``), None when unknown.
95
+ battery: Battery level in percent from ``getblehidstatus``; None while not connected.
96
+ The value can lag after a battery change.
97
+ rssi: Signal strength in dBm from ``getblehidstatus``; None while not connected.
98
+ """
99
+
100
+ paired: bool | None
101
+ connected: bool
102
+ name: str | None
103
+ mac: str | None = field(repr=False)
104
+ firmware: str | None
105
+ battery: int | None
106
+ rssi: int | None
107
+
108
+ def diagnostics_dict(self) -> dict[str, Any]:
109
+ """Dictionary safe for diagnostics: the BLE MAC is masked."""
110
+ return {
111
+ "paired": self.paired,
112
+ "connected": self.connected,
113
+ "name": self.name,
114
+ "mac": mask_mac(self.mac),
115
+ "firmware": self.firmware,
116
+ "battery": self.battery,
117
+ "rssi": self.rssi,
118
+ }
119
+
120
+
121
+ def parse_ble_remote_identity(parsed: Any) -> BleRemoteIdentity | None:
122
+ """Parse a ``getblehidstatus`` body; None when it is not a valid status object.
123
+
124
+ The real response includes ``"error":0``, so only a non-zero ``error`` marks an error wrapper.
125
+ """
126
+ if not isinstance(parsed, dict):
127
+ return None
128
+ status = parsed.get("status")
129
+ if not isinstance(status, str) or "name" not in parsed or "mac" not in parsed:
130
+ return None
131
+ error = parsed.get("error", 0)
132
+ if error not in (0, "0", None):
133
+ return None
134
+ name = parsed.get("name")
135
+ mac = parsed.get("mac")
136
+ name = name.strip() if isinstance(name, str) else ""
137
+ mac = mac.strip() if isinstance(mac, str) else ""
138
+ paired = bool(name) and bool(mac) and mac != _UNPAIRED_MAC
139
+ firmware = parsed.get("ver")
140
+ firmware = firmware.strip() if isinstance(firmware, str) else ""
141
+ return BleRemoteIdentity(
142
+ status=status,
143
+ paired=paired,
144
+ name=name or None if paired else None,
145
+ mac=mac if paired else None,
146
+ firmware=firmware or None if paired else None,
147
+ battery=_int_or_none(parsed.get("battery"), 0, 100),
148
+ rssi=_int_or_none(parsed.get("rssi")),
149
+ )
150
+
151
+
152
+ def _int_or_none(value: Any, low: int | None = None, high: int | None = None) -> int | None:
153
+ if isinstance(value, bool) or value is None:
154
+ return None
155
+ try:
156
+ number = int(str(value).strip())
157
+ except ValueError:
158
+ return None
159
+ if (low is not None and number < low) or (high is not None and number > high):
160
+ return None
161
+ return number
162
+
163
+
164
+ def build_ble_remote_state(identity: BleRemoteIdentity | None) -> BleRemoteState | None:
165
+ """Build remote state from one ``getblehidstatus`` read.
166
+
167
+ Battery and RSSI are None unless ``status`` is ``connected``. The battery value can lag after
168
+ a battery change. Returns None when the identity has not been read.
169
+ """
170
+ if identity is None:
171
+ return None
172
+ connected = identity.status == "connected"
173
+ return BleRemoteState(
174
+ paired=identity.paired,
175
+ connected=connected,
176
+ name=identity.name,
177
+ mac=identity.mac,
178
+ firmware=identity.firmware,
179
+ battery=identity.battery if connected else None,
180
+ rssi=identity.rssi if connected else None,
181
+ )
182
+
183
+
184
+ class BleRemoteAPI:
185
+ """WiiM Voice Remote mixin for the client. Read-only except the volume step."""
186
+
187
+ async def get_ble_remote_identity(self) -> BleRemoteIdentity | None:
188
+ """Read ``getblehidstatus``.
189
+
190
+ Returns:
191
+ The parsed identity, or None when the command is unsupported, the body is not a valid
192
+ status object, or the request failed.
193
+ """
194
+ try:
195
+ response = await self._request(API_ENDPOINT_BLE_REMOTE_STATUS) # type: ignore[attr-defined]
196
+ except WiiMError as err:
197
+ _LOGGER.debug("getblehidstatus failed: %s", err)
198
+ return None
199
+ return parse_ble_remote_identity(response.parsed)
200
+
201
+ async def get_remote_volume_step(self) -> int | None:
202
+ """Read the remote's volume step (1-5), or None when unreadable."""
203
+ try:
204
+ response = await self._request(API_ENDPOINT_REMOTE_VOLUME_STEP_GET) # type: ignore[attr-defined]
205
+ except WiiMError as err:
206
+ _LOGGER.debug("get_remote_volume_step failed: %s", err)
207
+ return None
208
+ if not isinstance(response.parsed, dict):
209
+ return None
210
+ return _int_or_none(response.parsed.get("remote_volume_step"), REMOTE_VOLUME_STEP_MIN, REMOTE_VOLUME_STEP_MAX)
211
+
212
+ async def set_remote_volume_step(self, step: int) -> int:
213
+ """Set the remote's volume step and verify it by reading it back.
214
+
215
+ Args:
216
+ step: 1 (Fine Adjustment) to 5 (Quick Adjustment); see ``REMOTE_VOLUME_STEPS``.
217
+
218
+ Returns:
219
+ The value the device reports after the write (equal to ``step``).
220
+
221
+ Raises:
222
+ ValueError: If ``step`` is not an int from 1 to 5 (nothing is sent).
223
+ WiiMError: If the device rejects the write, or the read-back is missing or differs.
224
+ """
225
+ if (
226
+ isinstance(step, bool)
227
+ or not isinstance(step, int)
228
+ or not (REMOTE_VOLUME_STEP_MIN <= step <= REMOTE_VOLUME_STEP_MAX)
229
+ ):
230
+ raise ValueError(
231
+ f"Remote volume step must be an integer between {REMOTE_VOLUME_STEP_MIN} "
232
+ f"and {REMOTE_VOLUME_STEP_MAX}, got {step!r}"
233
+ )
234
+ response = await self._request(f"{API_ENDPOINT_REMOTE_VOLUME_STEP_SET}{step}") # type: ignore[attr-defined]
235
+ parsed = response.parsed
236
+ if isinstance(parsed, dict) and str(parsed.get("status", "OK")).strip().upper() != "OK":
237
+ raise WiiMError(f"Device rejected remote volume step {step}: {parsed.get('status')!r}")
238
+ actual = await self.get_remote_volume_step()
239
+ if actual is None:
240
+ raise WiiMError(f"Remote volume step {step} was sent but could not be read back")
241
+ if actual != step:
242
+ raise WiiMError(f"Remote volume step set to {step} but the device reports {actual}")
243
+ return actual
@@ -466,6 +466,14 @@ API_ENDPOINT_SUBWOOFER_SET = "/httpapi.asp?command=setSubLPF:"
466
466
  API_ENDPOINT_TRIGGER_OUT_STATUS = "/httpapi.asp?command=getTriggeroutStatus"
467
467
  API_ENDPOINT_TRIGGER_OUT_SET = "/httpapi.asp?command=setTriggeroutStatus:"
468
468
 
469
+ # WiiM Voice Remote (Bluetooth LE). Read endpoints plus the volume step setting only.
470
+ # getblehidstatus → {"status":"connected|notconnect|scanning","name":..,"mac":..,..}
471
+ # get_remote_volume_step → {"status":"OK","remote_volume_step":1-5}; set_remote_volume_step:N → {"status":"OK"}
472
+ # Pairing, removal and firmware-update commands are deliberately not modelled (ADR 025).
473
+ API_ENDPOINT_BLE_REMOTE_STATUS = "/httpapi.asp?command=getblehidstatus"
474
+ API_ENDPOINT_REMOTE_VOLUME_STEP_GET = "/httpapi.asp?command=get_remote_volume_step"
475
+ API_ENDPOINT_REMOTE_VOLUME_STEP_SET = "/httpapi.asp?command=set_remote_volume_step:"
476
+
469
477
  # PEQ / GEQ endpoints - official WiiM LV2 EQ API
470
478
  # pluginURI (implemented in pywiim): http://moddevices.com/plugins/caps/EqNp
471
479
  # graphic 10-band pluginURI: http://moddevices.com/plugins/caps/Eq10HP
@@ -740,6 +748,9 @@ __all__ = [
740
748
  # Subwoofer endpoints and constants
741
749
  "API_ENDPOINT_SUBWOOFER_STATUS",
742
750
  "API_ENDPOINT_SUBWOOFER_SET",
751
+ "API_ENDPOINT_BLE_REMOTE_STATUS",
752
+ "API_ENDPOINT_REMOTE_VOLUME_STEP_GET",
753
+ "API_ENDPOINT_REMOTE_VOLUME_STEP_SET",
743
754
  "SUBWOOFER_CROSSOVER_MIN",
744
755
  "SUBWOOFER_CROSSOVER_MAX",
745
756
  "SUBWOOFER_LEVEL_MIN",
@@ -31,7 +31,9 @@ from typing import Any
31
31
  from urllib.parse import quote
32
32
 
33
33
  from .api.base import ApiResponse
34
+ from .api.ble_remote import parse_ble_remote_identity
34
35
  from .api.constants import (
36
+ API_ENDPOINT_BLE_REMOTE_STATUS,
35
37
  API_ENDPOINT_EQ_GET,
36
38
  API_ENDPOINT_EQ_LIST,
37
39
  API_ENDPOINT_EQ_STATUS,
@@ -106,7 +108,7 @@ def _channel_balance_probe_success(response: ApiResponse) -> bool:
106
108
  return True
107
109
 
108
110
 
109
- def _subwoofer_probe_error_definitively_unsupported(err: Exception) -> bool:
111
+ def _probe_error_definitively_unsupported(err: Exception) -> bool:
110
112
  """True when the error indicates the endpoint/command is not available."""
111
113
  s = str(err).lower()
112
114
  return "unknown command" in s or "404" in s or "not found" in s
@@ -146,7 +148,7 @@ async def _probe_supports_subwoofer(client: Any, device_info: DeviceInfo, capabi
146
148
  return False
147
149
  except Exception as err:
148
150
  last_err = err
149
- if _subwoofer_probe_error_definitively_unsupported(err):
151
+ if _probe_error_definitively_unsupported(err):
150
152
  _LOGGER.debug(
151
153
  "Subwoofer probe host=%s model=%s: unsupported (error=%s)",
152
154
  host,
@@ -169,6 +171,37 @@ async def _probe_supports_subwoofer(client: Any, device_info: DeviceInfo, capabi
169
171
  return None
170
172
 
171
173
 
174
+ async def _probe_supports_ble_remote(client: Any, device_info: DeviceInfo) -> bool | None:
175
+ """Read-only probe for WiiM Voice Remote support (ADR 025).
176
+
177
+ ``BleRemoteControl`` in ``getStatusEx`` is ``"1"`` whenever the speaker supports a remote,
178
+ whether or not one is paired. Only then is ``getblehidstatus`` read (a plain status read, no
179
+ pairing or scanning). Devices without the flag get False and no remote request at all.
180
+
181
+ Returns:
182
+ True if ``getblehidstatus`` returns a valid status object, False if the speaker does not
183
+ advertise a remote or the command is unsupported, None when the read was inconclusive
184
+ (transient error); the next refresh sets True once a read succeeds.
185
+ """
186
+ extra = device_info.model_extra or {}
187
+ if str(extra.get("BleRemoteControl", "")).strip() != "1":
188
+ return False
189
+
190
+ host = getattr(client, "host", "?")
191
+ try:
192
+ response = await client._request(API_ENDPOINT_BLE_REMOTE_STATUS)
193
+ except Exception as err:
194
+ if _probe_error_definitively_unsupported(err):
195
+ _LOGGER.debug("BLE remote probe host=%s: unsupported (error=%s)", host, err)
196
+ return False
197
+ _LOGGER.debug("BLE remote probe inconclusive for host=%s: %s", host, err)
198
+ return None
199
+ if parse_ble_remote_identity(response.parsed) is not None:
200
+ return True
201
+ _LOGGER.debug("BLE remote probe host=%s: unexpected response shape (%s)", host, type(response.parsed).__name__)
202
+ return False
203
+
204
+
172
205
  async def _probe_wiim_input_metadata(client: Any, capabilities: dict[str, Any]) -> None:
173
206
  """Probe input metadata and store it as a source overlay.
174
207
 
@@ -334,6 +367,7 @@ class WiiMCapabilities:
334
367
  capabilities.setdefault("supports_eq", True)
335
368
  capabilities.setdefault("supports_peq", False)
336
369
  capabilities.setdefault("supports_trigger_out", False)
370
+ capabilities.setdefault("supports_ble_remote", False)
337
371
  capabilities.setdefault("supports_led_switch", False)
338
372
  capabilities.setdefault("supports_display_config", False)
339
373
  capabilities.setdefault("supports_digital_filter", False)
@@ -601,6 +635,9 @@ class WiiMCapabilities:
601
635
  # Subwoofer (getSubLPF) — WiiM-only read probe; same endpoint as get_subwoofer_status_raw()
602
636
  capabilities["supports_subwoofer"] = await _probe_supports_subwoofer(client, device_info, capabilities)
603
637
 
638
+ # WiiM Voice Remote (ADR 025): BleRemoteControl from the device info already read, then getblehidstatus
639
+ capabilities["supports_ble_remote"] = await _probe_supports_ble_remote(client, device_info)
640
+
604
641
  # WiiM-only input metadata (capability list / enable flags / custom labels).
605
642
  # Read-only overlay on stable source ids; absent endpoints leave enumeration unchanged.
606
643
  await _probe_wiim_input_metadata(client, capabilities)
@@ -15,11 +15,13 @@ import argparse
15
15
  import asyncio
16
16
  import json
17
17
  import logging
18
+ import re
18
19
  import sys
19
20
  from dataclasses import asdict, is_dataclass
20
21
  from datetime import datetime
21
22
  from typing import Any
22
23
 
24
+ from ..api.ble_remote import REMOTE_VOLUME_STEPS, build_ble_remote_state
23
25
  from ..api.constants import API_ENDPOINT_GET_DIGITAL_FILTER_TYPES
24
26
  from ..api.misc import parse_digital_filter_types
25
27
  from ..client import WiiMClient
@@ -28,6 +30,8 @@ from ..player import Player
28
30
 
29
31
  _LOGGER = logging.getLogger(__name__)
30
32
 
33
+ _MAC_RE = re.compile(r"(?i)\b(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2}\b")
34
+
31
35
 
32
36
  class DeviceDiagnostics:
33
37
  """Comprehensive diagnostic tool for WiiM devices."""
@@ -65,6 +69,7 @@ class DeviceDiagnostics:
65
69
  await self._gather_status()
66
70
  await self._gather_debug_info()
67
71
  await self._gather_discovered_api_info()
72
+ await self._gather_ble_remote_info()
68
73
  await self._test_endpoints()
69
74
  await self._test_features()
70
75
 
@@ -235,6 +240,40 @@ class DeviceDiagnostics:
235
240
 
236
241
  self.report["discovered_apis"] = discovered
237
242
 
243
+ async def _gather_ble_remote_info(self) -> None:
244
+ """Add the WiiM Voice Remote section when the speaker supports a remote (read-only, ADR 025).
245
+
246
+ Built from ``getblehidstatus`` only (BLE MAC masked) plus the volume step. The raw body
247
+ is never stored, and nothing is written to the device.
248
+ """
249
+ if not self.client._capabilities_detected:
250
+ await self.client._detect_capabilities()
251
+ if self.client.capabilities.get("supports_ble_remote") is not True:
252
+ return
253
+
254
+ print("\n🎛 Reading WiiM Voice Remote state...")
255
+ try:
256
+ state = build_ble_remote_state(await self.client.get_ble_remote_identity())
257
+ if state is None:
258
+ self.report["ble_remote"] = {"supported": True, "error": "unreadable"}
259
+ print(" ⚠ Remote state: unreadable")
260
+ return
261
+ step = await self.client.get_remote_volume_step()
262
+ self.report["ble_remote"] = {
263
+ "supported": True,
264
+ **state.diagnostics_dict(),
265
+ "volume_step": step,
266
+ "volume_step_label": REMOTE_VOLUME_STEPS.get(step) if step is not None else None,
267
+ }
268
+ print(f" ✓ Remote: paired={state.paired} connected={state.connected} battery={state.battery}")
269
+ except Exception as err:
270
+ self.report["ble_remote"] = {
271
+ "supported": True,
272
+ "error": _MAC_RE.sub("XX:XX:XX:XX:XX:XX", str(err)),
273
+ "error_type": type(err).__name__,
274
+ }
275
+ print(f" ⚠ Remote state: {type(err).__name__}")
276
+
238
277
  async def _test_endpoints(self) -> None:
239
278
  """Test various API endpoints."""
240
279
  print("\n🧪 Testing API endpoints...")
@@ -1238,6 +1277,7 @@ Examples:
1238
1277
  print(f" Device: {client.host}:{client.port}\n")
1239
1278
  await diagnostics._gather_device_info()
1240
1279
  await diagnostics._gather_discovered_api_info()
1280
+ await diagnostics._gather_ble_remote_info()
1241
1281
  else:
1242
1282
  await diagnostics.run_full_diagnostic()
1243
1283
  diagnostics.print_report()
@@ -16,6 +16,7 @@ from aiohttp import ClientSession
16
16
 
17
17
  from .api.audio_settings import AudioSettingsAPI
18
18
  from .api.base import BaseWiiMClient
19
+ from .api.ble_remote import BleRemoteAPI
19
20
  from .api.bluetooth import BluetoothAPI
20
21
  from .api.device import DeviceAPI
21
22
  from .api.diagnostics import DiagnosticsAPI
@@ -47,6 +48,7 @@ class WiiMClient(
47
48
  BluetoothAPI,
48
49
  AudioSettingsAPI,
49
50
  SubwooferAPI,
51
+ BleRemoteAPI,
50
52
  LMSAPI,
51
53
  MiscAPI,
52
54
  DeviceAPI,
@@ -248,6 +250,7 @@ class WiiMClient(
248
250
  if upnp_caps:
249
251
  capabilities.update(upnp_caps)
250
252
  capabilities.setdefault("supports_subwoofer", False)
253
+ capabilities.setdefault("supports_ble_remote", False)
251
254
  self._capabilities.update(capabilities)
252
255
  self._capabilities_detected = True
253
256
  await self._apply_protocol_preference()