Skip to content

feat: support Home Assistant clean_area (room cleaning) for vacuum#1743

Open
eduardobittencourt wants to merge 1 commit into
XiaoMi:mainfrom
eduardobittencourt:feat/vacuum-clean-area
Open

feat: support Home Assistant clean_area (room cleaning) for vacuum#1743
eduardobittencourt wants to merge 1 commit into
XiaoMi:mainfrom
eduardobittencourt:feat/vacuum-clean-area

Conversation

@eduardobittencourt

Copy link
Copy Markdown

Summary

Adds support for Home Assistant core's native vacuum.clean_area service (the CLEAN_AREA feature, available in recent HA core). Users can clean specific rooms by selecting Home Assistant areas; HA maps those areas to the vacuum's rooms (segments) and the integration tells the robot to clean them.

This complements send_command / app_segment_clean (e.g. #1702): it wires room cleaning into HA's first-class areas UI instead of requiring raw room ids in automations.

How it works

HA core does the heavy lifting (the area↔segment mapping dialog + storage, and the vacuum.clean_area service). An integration only needs to:

  1. set VacuumEntityFeature.CLEAN_AREA,
  2. implement async_get_segments() → the device's rooms,
  3. implement async_clean_segments(segment_ids) → start a room sweep.

This PR maps those onto the standard MIoT spec:

  • async_get_segments() reads the room-information property ({"rooms":[{"id","name"}]}) → Segment(id, name).
  • async_clean_segments() calls the start-vacuum-room-sweep action with vacuum-room-ids as a JSON array string (e.g. "[3, 10]").

Everything is capability-gated and version-guarded:

  • CLEAN_AREA is enabled only when the device exposes both room-information and start-vacuum-room-sweep, so models without room cleaning are unaffected.
  • Segment / CLEAN_AREA are imported behind try/except + hasattr, so older HA core keeps working unchanged.

Changes

  • vacuum.py: capture the room property/action, enable CLEAN_AREA, add async_get_segments / async_clean_segments.
  • miot/specs/specv2entity.py: route room-information and start-vacuum-room-sweep into the vacuum entity (as optional).

Test plan

Tested on xiaomi.vacuum.d102gl (HA core 2026.6):

  • vacuum.clean_area lists the vacuum (CLEAN_AREA feature present).
  • The HA area → room mapping dialog shows the robot's rooms (async_get_segments).
  • Cleaning one area (Living room) cleans that room.
  • Cleaning multiple areas (Living room + Kitchen) cleans both — payload "[3, 10]".
  • pylint clean on the changed lines (no new warnings).

Notes

  • The vacuum-room-ids string is firmware-defined (the spec only types it as str). The JSON array form works on the d102gl and matches the app_segment_clean payload in feat: add complete support of S40 pro vacuum #1702; confirmation on other models is welcome.
  • Could be extended to zone cleaning (start-zone-sweep) the same way.

Implement Home Assistant core's CLEAN_AREA vacuum feature so users can
clean specific rooms by selecting Home Assistant areas
(vacuum.clean_area). HA core handles the area<->segment mapping UI and
storage; the integration only needs to expose the device's rooms and
trigger a room sweep.

- vacuum.py:
  - Capture the standard MIoT 'room-information' property and the
    'start-vacuum-room-sweep' action; enable
    VacuumEntityFeature.CLEAN_AREA when both are present and the running
    HA core supports the feature (guarded import so older cores keep
    working unchanged).
  - async_get_segments(): parse 'room-information' into Segment(id, name).
  - async_clean_segments(): send the selected room ids to the device via
    the room-sweep action. 'vacuum-room-ids' is a JSON array string
    (e.g. "[3, 10]"), consistent with the app_segment_clean payload in
    XiaoMi#1702.
- specv2entity.py: route 'room-information' and 'start-vacuum-room-sweep'
  into the vacuum entity (optional, so models without them are
  unaffected).

Tested on xiaomi.vacuum.d102gl: mapping Home Assistant areas to rooms and
calling vacuum.clean_area cleans the selected rooms (single and multiple).
@CLAassistant

CLAassistant commented Jun 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@eduardobittencourt
eduardobittencourt marked this pull request as ready for review June 26, 2026 18:27
@gzamboni

Copy link
Copy Markdown

@SusanPhevos this is a long waited feature to vacuum robots. This PR gonna be a quality of life update for real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants