Skip to content

Commit 8a4b2c5

Browse files
committed
fix(a01): skip unsupported DPs in Zeo query_values
1 parent 71fde3b commit 8a4b2c5

3 files changed

Lines changed: 77 additions & 15 deletions

File tree

‎roborock/devices/traits/a01/__init__.py‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from roborock.devices.traits.a01.device_feature import (
6868
build_feature_dp_list,
6969
build_force_load_dp_list,
70+
supports_dp,
7071
supports_uv_light,
7172
)
7273
from roborock.devices.traits.common import TraitUpdateListener
@@ -442,13 +443,23 @@ def supports(self, feature: ZeoFeatureBits) -> bool:
442443
return bool(self._feature_bits & (1 << feature.value))
443444

444445
async def query_values(self, protocols: list[RoborockZeoProtocol]) -> dict[RoborockZeoProtocol, Any]:
445-
"""Query the device for the values of the given protocols."""
446-
response = await send_decoded_command(
447-
self._channel,
448-
{RoborockZeoProtocol.ID_QUERY: protocols},
449-
value_encoder=json.dumps,
450-
)
451-
values = {protocol: convert_zeo_value(protocol, response.get(protocol)) for protocol in protocols}
446+
"""Query the device for the values of the given protocols.
447+
448+
Protocols the device model is known not to support are not sent to the
449+
device, since it would never answer them, and are returned as None.
450+
"""
451+
supported = [protocol for protocol in protocols if supports_dp(self._model, protocol)]
452+
response: dict[RoborockZeoProtocol, Any] = {}
453+
if supported:
454+
response = await send_decoded_command(
455+
self._channel,
456+
{RoborockZeoProtocol.ID_QUERY: supported},
457+
value_encoder=json.dumps,
458+
)
459+
values = {
460+
protocol: convert_zeo_value(protocol, response[protocol]) if protocol in response else None
461+
for protocol in protocols
462+
}
452463
self._merge_query_response(values)
453464
return values
454465

‎roborock/devices/traits/a01/device_feature.py‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@
223223
RoborockZeoProtocol.F_C, # 10001
224224
]
225225

226+
# DPs only answered by models with a softener compartment.
227+
_SOFTENER_DPS: list[RoborockZeoProtocol] = [
228+
RoborockZeoProtocol.SOFTENER_SET, # 212
229+
RoborockZeoProtocol.SOFTENER_TYPE, # 214
230+
RoborockZeoProtocol.DEFAULT_SETTING, # 225
231+
RoborockZeoProtocol.SOFTENER_EMPTY, # 227
232+
]
233+
226234

227235
# ── Public helpers ──────────────────────────────────────────────────────
228236

@@ -259,6 +267,21 @@ def supports_default_setting(model: str | None) -> bool:
259267
return model not in _UNSUPPORTED_DEFAULT_SETTING
260268

261269

270+
def supports_dp(model: str | None, dp: RoborockZeoProtocol) -> bool:
271+
"""Return False if *model* is known to never answer a query for *dp*.
272+
273+
A query only completes once every requested DP is answered, so asking a
274+
device for a DP it lacks makes the whole query time out.
275+
"""
276+
if dp == RoborockZeoProtocol.FEATURE_BITS:
277+
return supports_feature_bits(model)
278+
if dp == RoborockZeoProtocol.DEFAULT_SETTING and not supports_default_setting(model):
279+
return False
280+
if dp in _SOFTENER_DPS:
281+
return has_softener_compartment(model)
282+
return True
283+
284+
262285
def supports_remote_control(model: str | None) -> bool:
263286
"""Remote control (DP 232) is supported on all overseas models."""
264287
if model is None:
@@ -291,14 +314,7 @@ def build_force_load_dp_list(model: str | None) -> list[RoborockZeoProtocol]:
291314

292315
# ── Softener block (212, 214, 225, 227) ──
293316
if has_softener_compartment(model):
294-
base.extend(
295-
[
296-
RoborockZeoProtocol.SOFTENER_SET, # 212
297-
RoborockZeoProtocol.SOFTENER_TYPE, # 214
298-
RoborockZeoProtocol.DEFAULT_SETTING, # 225
299-
RoborockZeoProtocol.SOFTENER_EMPTY, # 227
300-
]
301-
)
317+
base.extend(_SOFTENER_DPS)
302318

303319
# ── Smart-hosting DPs (always queried when FEATURE_BITS is supported) ──
304320
if supports_feature_bits(model):

‎tests/devices/traits/a01/test_init.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,41 @@ async def test_dyad_action_commands(
538538
assert payload_data["dps"] == expected_dps
539539

540540

541+
async def test_zeo_api_query_values_skips_unsupported_dps(fake_channel: FakeChannel):
542+
"""Zeo Mini (a93) has no softener compartment and never answers the softener DPs."""
543+
zeo_api = ZeoApi(fake_channel, model="roborock.wm.a93") # type: ignore[arg-type]
544+
fake_channel.response_queue.append(build_a01_message({203: 4, 226: 1}))
545+
546+
result = await zeo_api.query_values(
547+
[
548+
RoborockZeoProtocol.STATE,
549+
RoborockZeoProtocol.DETERGENT_EMPTY,
550+
RoborockZeoProtocol.SOFTENER_TYPE,
551+
RoborockZeoProtocol.SOFTENER_EMPTY,
552+
]
553+
)
554+
555+
assert result == {
556+
RoborockZeoProtocol.STATE: "washing",
557+
RoborockZeoProtocol.DETERGENT_EMPTY: True,
558+
RoborockZeoProtocol.SOFTENER_TYPE: None,
559+
RoborockZeoProtocol.SOFTENER_EMPTY: None,
560+
}
561+
assert len(fake_channel.published_messages) == 1
562+
payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size))
563+
assert payload_data["dps"] == {"10000": "[203, 226]"}
564+
565+
566+
async def test_zeo_api_query_values_only_unsupported_dps(fake_channel: FakeChannel):
567+
"""Nothing is sent when the device supports none of the requested DPs."""
568+
zeo_api = ZeoApi(fake_channel, model="roborock.wm.a93") # type: ignore[arg-type]
569+
570+
result = await zeo_api.query_values([RoborockZeoProtocol.SOFTENER_EMPTY])
571+
572+
assert result == {RoborockZeoProtocol.SOFTENER_EMPTY: None}
573+
assert not fake_channel.published_messages
574+
575+
541576
async def test_zeo_api_set_value(zeo_api: ZeoApi, fake_channel: FakeChannel):
542577
"""Test ZeoApi set_value sends correct command."""
543578
await zeo_api.set_value(RoborockZeoProtocol.MODE, "standard")

0 commit comments

Comments
 (0)