Skip to content

Commit 5db7ae4

Browse files
committed
fix: try to fix fan setting
1 parent 5c16930 commit 5db7ae4

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

roborock/data/b01_q7/b01_q7_code_mappings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class SCWindMapping(RoborockModeEnum):
2424
STANDARD = ("balanced", 1)
2525
STRONG = ("turbo", 2)
2626
SUPER_STRONG = ("max", 3)
27-
MAX = ("max_plus", 4)
2827

2928

3029
class WaterLevelMapping(RoborockModeEnum):

roborock/devices/b01_channel.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ async def send_decoded_command(
2828
dps: int,
2929
command: CommandType,
3030
params: ParamsType,
31-
) -> dict[str, Any]:
32-
"""Send a command on the MQTT channel and get a decoded response."""
31+
) -> Any:
32+
"""Send a command on the MQTT channel and get a decoded response.
33+
34+
Note: B01 "set" commands may return a scalar (e.g. 0/"ok") rather than a dict.
35+
"""
3336
_LOGGER.debug("Sending MQTT command: %s", params)
3437
msg_id = str(get_next_int(100000000000, 999999999999))
3538
roborock_message = encode_mqtt_payload(dps, command, params, msg_id)
36-
future: asyncio.Future[dict[str, Any]] = asyncio.get_running_loop().create_future()
39+
future: asyncio.Future[Any] = asyncio.get_running_loop().create_future()
3740

3841
def find_response(response_message: RoborockMessage) -> None:
3942
"""Handle incoming messages and resolve the future."""
@@ -59,10 +62,7 @@ def find_response(response_message: RoborockMessage) -> None:
5962
_LOGGER.debug("Received query response: %s", inner)
6063
data = inner.get("data")
6164
if not future.done():
62-
if isinstance(data, dict):
63-
future.set_result(data)
64-
else:
65-
future.set_exception(RoborockException(f"Unexpected data type for response: {data}"))
65+
future.set_result(data)
6666

6767
unsub = await mqtt_channel.subscribe(find_response)
6868

roborock/devices/traits/b01/q7/__init__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ async def query_values(self, props: list[RoborockB01Props]) -> B01Props | None:
3636
command=RoborockB01Q7Methods.GET_PROP,
3737
params={"property": props},
3838
)
39+
if not isinstance(result, dict):
40+
raise TypeError(f"Unexpected response type for GET_PROP: {type(result).__name__}: {result!r}")
3941
return B01Props.from_dict(result)
4042

41-
async def set_prop(self, prop: RoborockB01Props, value: Any) -> dict[str, Any]:
43+
async def set_prop(self, prop: RoborockB01Props, value: Any) -> Any:
4244
"""Set a property on the device."""
4345
return await send_decoded_command(
4446
self._channel,
@@ -47,15 +49,15 @@ async def set_prop(self, prop: RoborockB01Props, value: Any) -> dict[str, Any]:
4749
params={prop: value},
4850
)
4951

50-
async def set_fan_speed(self, fan_speed: SCWindMapping) -> dict[str, Any]:
52+
async def set_fan_speed(self, fan_speed: SCWindMapping) -> Any:
5153
"""Set the fan speed (wind)."""
5254
return await self.set_prop(RoborockB01Props.WIND, fan_speed.code)
5355

54-
async def set_water_level(self, water_level: WaterLevelMapping) -> dict[str, Any]:
56+
async def set_water_level(self, water_level: WaterLevelMapping) -> Any:
5557
"""Set the water level (water)."""
5658
return await self.set_prop(RoborockB01Props.WATER, water_level.code)
5759

58-
async def start_clean(self) -> dict[str, Any]:
60+
async def start_clean(self) -> Any:
5961
"""Start cleaning."""
6062
return await send_decoded_command(
6163
self._channel,
@@ -68,7 +70,7 @@ async def start_clean(self) -> dict[str, Any]:
6870
},
6971
)
7072

71-
async def pause_clean(self) -> dict[str, Any]:
73+
async def pause_clean(self) -> Any:
7274
"""Pause cleaning."""
7375
return await send_decoded_command(
7476
self._channel,
@@ -81,7 +83,7 @@ async def pause_clean(self) -> dict[str, Any]:
8183
},
8284
)
8385

84-
async def stop_clean(self) -> dict[str, Any]:
86+
async def stop_clean(self) -> Any:
8587
"""Stop cleaning."""
8688
return await send_decoded_command(
8789
self._channel,
@@ -94,7 +96,7 @@ async def stop_clean(self) -> dict[str, Any]:
9496
},
9597
)
9698

97-
async def return_to_dock(self) -> dict[str, Any]:
99+
async def return_to_dock(self) -> Any:
98100
"""Return to dock."""
99101
return await send_decoded_command(
100102
self._channel,
@@ -103,7 +105,7 @@ async def return_to_dock(self) -> dict[str, Any]:
103105
params={},
104106
)
105107

106-
async def find_me(self) -> dict[str, Any]:
108+
async def find_me(self) -> Any:
107109
"""Locate the robot."""
108110
return await send_decoded_command(
109111
self._channel,

roborock/protocols/b01_protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def encode_mqtt_payload(dps: int, command: CommandType, params: ParamsType, msg_
2828
dps: {
2929
"method": str(command),
3030
"msgId": msg_id,
31-
"params": params or [],
31+
# Important: some B01 methods use an empty object `{}` (not `[]`) for
32+
# "no params", and some setters legitimately send `0` which is falsy.
33+
# Only default to `[]` when params is actually None.
34+
"params": params if params is not None else [],
3235
}
3336
}
3437
}

roborock/roborock_typing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,14 @@ class RoborockCommand(str, Enum):
280280
class RoborockB01Q7Methods(StrEnum):
281281
"""Methods used by the Roborock Q7 model."""
282282

283+
# NOTE: In the Q7 Hermes dump these appear as suffixes and are also used
284+
# with an "event." prefix at runtime (see `hermes/.../module_524.js`).
283285
ADD_CLEAN_FAILED_POST = "add_clean_failed.post"
286+
EVENT_ADD_CLEAN_FAILED_POST = "event.add_clean_failed.post"
284287
CLEAN_FINISH_POST = "clean_finish.post"
288+
EVENT_CLEAN_FINISH_POST = "event.clean_finish.post"
285289
EVENT_BUILD_MAP_FINISH_POST = "event.BuildMapFinish.post"
286290
EVENT_MAP_CHANGE_POST = "event.map_change.post"
287-
EVENT_TYPE = "event.type"
288291
EVENT_WORK_APPOINT_CLEAN_FAILED_POST = "event.work_appoint_clean_failed.post"
289292
START_CLEAN_POST = "startClean.post"
290293
ADD_ORDER = "service.add_order"
@@ -338,7 +341,6 @@ class RoborockB01Q7Methods(StrEnum):
338341
GET_PREFERENCE = "service.get_preference"
339342
GET_RECORD_LIST = "service.get_record_list"
340343
GET_ORDER = "service.get_order"
341-
EVENT_ORDER_LIST_POST = "event.order_list.post"
342344
POST_PROP = "prop.post"
343345

344346

0 commit comments

Comments
 (0)