diff --git a/roborock/devices/traits/a01/__init__.py b/roborock/devices/traits/a01/__init__.py index 7682bc7f8..a3a9b46d0 100644 --- a/roborock/devices/traits/a01/__init__.py +++ b/roborock/devices/traits/a01/__init__.py @@ -67,6 +67,7 @@ from roborock.devices.traits.a01.device_feature import ( build_feature_dp_list, build_force_load_dp_list, + supports_dp, supports_uv_light, ) from roborock.devices.traits.common import TraitUpdateListener @@ -442,13 +443,23 @@ def supports(self, feature: ZeoFeatureBits) -> bool: return bool(self._feature_bits & (1 << feature.value)) async def query_values(self, protocols: list[RoborockZeoProtocol]) -> dict[RoborockZeoProtocol, Any]: - """Query the device for the values of the given protocols.""" - response = await send_decoded_command( - self._channel, - {RoborockZeoProtocol.ID_QUERY: protocols}, - value_encoder=json.dumps, - ) - values = {protocol: convert_zeo_value(protocol, response.get(protocol)) for protocol in protocols} + """Query the device for the values of the given protocols. + + Protocols the device model is known not to support are not sent to the + device, since it would never answer them, and are returned as None. + """ + supported = [protocol for protocol in protocols if supports_dp(self._model, protocol)] + response: dict[RoborockZeoProtocol, Any] = {} + if supported: + response = await send_decoded_command( + self._channel, + {RoborockZeoProtocol.ID_QUERY: supported}, + value_encoder=json.dumps, + ) + values = { + protocol: convert_zeo_value(protocol, response[protocol]) if protocol in response else None + for protocol in protocols + } self._merge_query_response(values) return values diff --git a/roborock/devices/traits/a01/device_feature.py b/roborock/devices/traits/a01/device_feature.py index 3290833d7..a09686cc5 100644 --- a/roborock/devices/traits/a01/device_feature.py +++ b/roborock/devices/traits/a01/device_feature.py @@ -223,6 +223,14 @@ RoborockZeoProtocol.F_C, # 10001 ] +# DPs only answered by models with a softener compartment. +_SOFTENER_DPS: list[RoborockZeoProtocol] = [ + RoborockZeoProtocol.SOFTENER_SET, # 212 + RoborockZeoProtocol.SOFTENER_TYPE, # 214 + RoborockZeoProtocol.DEFAULT_SETTING, # 225 + RoborockZeoProtocol.SOFTENER_EMPTY, # 227 +] + # ── Public helpers ────────────────────────────────────────────────────── @@ -259,6 +267,21 @@ def supports_default_setting(model: str | None) -> bool: return model not in _UNSUPPORTED_DEFAULT_SETTING +def supports_dp(model: str | None, dp: RoborockZeoProtocol) -> bool: + """Return False if *model* is known to never answer a query for *dp*. + + A query only completes once every requested DP is answered, so asking a + device for a DP it lacks makes the whole query time out. + """ + if dp == RoborockZeoProtocol.FEATURE_BITS: + return supports_feature_bits(model) + if dp == RoborockZeoProtocol.DEFAULT_SETTING and not supports_default_setting(model): + return False + if dp in _SOFTENER_DPS: + return has_softener_compartment(model) + return True + + def supports_remote_control(model: str | None) -> bool: """Remote control (DP 232) is supported on all overseas models.""" if model is None: @@ -291,14 +314,7 @@ def build_force_load_dp_list(model: str | None) -> list[RoborockZeoProtocol]: # ── Softener block (212, 214, 225, 227) ── if has_softener_compartment(model): - base.extend( - [ - RoborockZeoProtocol.SOFTENER_SET, # 212 - RoborockZeoProtocol.SOFTENER_TYPE, # 214 - RoborockZeoProtocol.DEFAULT_SETTING, # 225 - RoborockZeoProtocol.SOFTENER_EMPTY, # 227 - ] - ) + base.extend(_SOFTENER_DPS) # ── Smart-hosting DPs (always queried when FEATURE_BITS is supported) ── if supports_feature_bits(model): diff --git a/tests/devices/traits/a01/test_init.py b/tests/devices/traits/a01/test_init.py index aea824e6f..84fd4b11b 100644 --- a/tests/devices/traits/a01/test_init.py +++ b/tests/devices/traits/a01/test_init.py @@ -538,6 +538,41 @@ async def test_dyad_action_commands( assert payload_data["dps"] == expected_dps +async def test_zeo_api_query_values_skips_unsupported_dps(fake_channel: FakeChannel): + """Zeo Mini (a93) has no softener compartment and never answers the softener DPs.""" + zeo_api = ZeoApi(fake_channel, model="roborock.wm.a93") # type: ignore[arg-type] + fake_channel.response_queue.append(build_a01_message({203: 4, 226: 1})) + + result = await zeo_api.query_values( + [ + RoborockZeoProtocol.STATE, + RoborockZeoProtocol.DETERGENT_EMPTY, + RoborockZeoProtocol.SOFTENER_TYPE, + RoborockZeoProtocol.SOFTENER_EMPTY, + ] + ) + + assert result == { + RoborockZeoProtocol.STATE: "washing", + RoborockZeoProtocol.DETERGENT_EMPTY: True, + RoborockZeoProtocol.SOFTENER_TYPE: None, + RoborockZeoProtocol.SOFTENER_EMPTY: None, + } + assert len(fake_channel.published_messages) == 1 + payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size)) + assert payload_data["dps"] == {"10000": "[203, 226]"} + + +async def test_zeo_api_query_values_only_unsupported_dps(fake_channel: FakeChannel): + """Nothing is sent when the device supports none of the requested DPs.""" + zeo_api = ZeoApi(fake_channel, model="roborock.wm.a93") # type: ignore[arg-type] + + result = await zeo_api.query_values([RoborockZeoProtocol.SOFTENER_EMPTY]) + + assert result == {RoborockZeoProtocol.SOFTENER_EMPTY: None} + assert not fake_channel.published_messages + + async def test_zeo_api_set_value(zeo_api: ZeoApi, fake_channel: FakeChannel): """Test ZeoApi set_value sends correct command.""" await zeo_api.set_value(RoborockZeoProtocol.MODE, "standard")