Add selective room cleaning to vacuum clean module#1660
Conversation
Add clean_rooms() to send selective room clean commands using clean_mode 3 with the verified setSwitchClean payload, and get_rooms() to query the room list from the device on demand. Add getMapInfo to the polling query to expose current_map_id. Tested on RV30 Max Plus (EU) firmware 1.3.2.
3a5234c to
cba457a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1660 +/- ##
==========================================
+ Coverage 93.22% 93.29% +0.06%
==========================================
Files 157 157
Lines 9818 9932 +114
Branches 1003 1022 +19
==========================================
+ Hits 9153 9266 +113
+ Misses 472 471 -1
- Partials 193 195 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rytilahti
left a comment
There was a problem hiding this comment.
Thanks for the pull request, @epg-pers! See some initial comments inline.
I am trying to think ahead how to integrate this with downstreams, I guess we would need to add support for parameters for Feature actions to make it easier to integrate, e.g., to home assistant?
|
Hello! @epg-pers I tested this with my RV30(UN) 1.0, firmware 1.2.2 Build 240627, AES transport, and it worked beautifully! I took a stab at integrating zones too, and it worked, but I would have never managed without your work! In order to progress with different modes, I triggered each cleaning mode from the Tapo app (room, zone, custom, home advanced, home standard) and polled getCleanStatus / getSwitchClean / getVacStatus via the local API to observe which clean_status and clean_mode values the device reported. Then I replayed those values in setSwitchClean payloads locally and verified that the vacuum actually started the expected mode (checked by looking at the vacuum IRL and via the app). One thing I couldn't figure out and trigger properly is the "Home Advanced Cleaning", but the others (spot, rooms, zones) would be covered. In case you're curious, I extended this also trying to factor in @rytilahti's suggestions here master...davidefiocco:python-kasa:feat/room-cleaning-improvements in case it can be useful for inspiration (and zones could be added in a separate PR). It worked for me! |
That's great do hear. It sounds like you followed a similar strategy to me; trigger action from the app > poll the device locally to understand what was set > attempt the same payload locally. Feel free to add your additions to this PR. I haven't had much time this week to revisit @rytilahti suggestions. |
…ding for room cleaning
Sure! @epg-pers, I've prepared a commit addressing @rytilahti's review feedback (enums, dataclasses, base64 name decoding, clean_type property) with rooms only, no zones yet. All 54 tests pass and pre-commit checks are clean. You could either:
And if needed I can try to chime in response to @rytilahti's comments above. |
|
@davidefiocco thanks for doing the legwork on rytilahti's suggestions, ive merged your branch in. 54 tests passing and pre-commit clean. @rytilahti really appreciate the detailed review feedback, the enums, dataclass, and base64 name decoding are all in now. Let me know if there is anything else you would like changed. |
rytilahti
left a comment
There was a problem hiding this comment.
Just a couple of minor nits, nice to see the progress here! Feel free to comment and/or close my previous comments, just to make it visible if they are still pending.
|
Hey @epg-pers ! You can check the new diff via epg-pers/python-kasa@feature/vacuum-room-cleaning...davidefiocco:python-kasa:feature/vacuum-room-cleaning-review-fixes and merge on your branch via git fetch davidefiocco feature/vacuum-room-cleaning-review-fixes
git merge davidefiocco/feature/vacuum-room-cleaning-review-fixesThis time I addressed debug logging, the requested blank line and typed I also added a fixture from my device, and added that separately in #1665, but couldn't add map data in it yet (I experience errors if I try). |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
|
@davidefiocco, I merged your branch to @epg-pers' branch behind this PR, thanks to both of you for this! I tested with my own vacuum & I am planning to improve this with some ideas I have in a separate PR, so I will just merge this now. |
|
Fantastic news, thanks for consolidating this @rytilahti!! |
Summary
Adds support for selective room cleaning to the existing
Cleanmodule:clean_rooms(room_ids: list[int], map_id: int | None = None)- sendssetSwitchCleanwithclean_mode: 3and the verified payload to clean specific roomsget_rooms(map_id: int | None = None)- on-demand call togetMapDatareturning the filtered list of room areascurrent_map_idproperty - exposes the active map ID fromgetMapInfo, which is now included in the polling queryBackground
The correct
setSwitchCleanpayload for selective room cleaning was reverse-engineered by intercepting live device traffic while the official Tapo app performed a room clean (getSwitchCleanreadback). Key findings:clean_mode: 2is spot clean — theroom_listfield is silently ignoredclean_mode: 3is selective room cleanroom_listis a plainint[]of room IDs (the pixel values used in the LZ4 map), not an array of objectsstart_type: 1is requiredThis was verified working on an RV30 Max Plus (EU) running firmware 1.3.2, documented in https://github.com/epg-pers/tapo-rv30-ha and discussed in #1592.
Test plan
test_clean_rooms- verifies correctsetSwitchCleanpayload with default map IDtest_clean_rooms_explicit_map_id- verifies explicitmap_idis used when providedtest_clean_rooms_empty_raises- verifiesValueErroron empty room listtest_get_rooms/test_get_rooms_explicit_map_id- verifiesgetMapDatacall and room filtering