Skip to content

Overhaul Roborock integration to use new devices based API#154837

Merged
edenhaus merged 23 commits intohome-assistant:devfrom
allenporter:roborock-v2
Nov 26, 2025
Merged

Overhaul Roborock integration to use new devices based API#154837
edenhaus merged 23 commits intohome-assistant:devfrom
allenporter:roborock-v2

Conversation

@allenporter
Copy link
Copy Markdown
Contributor

@allenporter allenporter commented Oct 19, 2025

Proposed change

This is a large PR rewriting the integration and is a work in progress. This is expected to improve reliability since it uses a single MQTT session for all devices, and improves startup time by caching connection information so that we can connect to devices locally without hitting the cloud at all.

This moves a significant portion of the integration code behind the API boundary, reducing the amount of protocol specific details in the integration. This PR attempts to minimize diffs where possible, leaving some opportunities for future cleanup to reduce the amount of integration code further.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown

Hey there @Lash-L, mind taking a look at this pull request as it has been labeled with an integration (roborock) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of roborock can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign roborock Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Roborock integration to use a new device-based API architecture, replacing the older coordinator and entity patterns with a more modern trait-based approach.

  • Introduces new device manager and properties API structure
  • Migrates from old coordinator patterns to new trait-based device interactions
  • Replaces manual API calls with structured device properties and commands

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
homeassistant/components/roborock/init.py Replaced old device setup with new device manager pattern
homeassistant/components/roborock/coordinator.py Overhauled coordinator architecture with new trait-based API
homeassistant/components/roborock/vacuum.py Updated vacuum entity to use new coordinator and device patterns
homeassistant/components/roborock/sensor.py Migrated sensor entities to new coordinator structure
homeassistant/components/roborock/switch.py Converted to trait-based switch implementations
homeassistant/components/roborock/time.py Updated time entities to use trait-based patterns
homeassistant/components/roborock/number.py Migrated number entities to new trait system
homeassistant/components/roborock/button.py Updated button entities with new consumable trait approach
homeassistant/components/roborock/image.py Simplified image entity to use new coordinator pattern
homeassistant/components/roborock/entity.py Removed old entity base classes (no longer needed)
tests/components/roborock/conftest.py Overhauled test fixtures to support new device structure
tests/components/roborock/test_*.py Updated all test files to use new fake device patterns

Comment thread homeassistant/components/roborock/sensor.py Outdated
Comment thread homeassistant/components/roborock/switch.py Outdated
Comment thread homeassistant/components/roborock/time.py Outdated
Comment thread homeassistant/components/roborock/time.py Outdated
Comment thread homeassistant/components/roborock/switch.py Outdated
Comment thread homeassistant/components/roborock/number.py Outdated
Comment thread homeassistant/components/roborock/image.py Outdated
Comment thread homeassistant/components/roborock/sensor.py Outdated
Comment thread homeassistant/components/roborock/sensor.py Outdated
Comment thread tests/components/roborock/test_number.py Outdated
@Lash-L
Copy link
Copy Markdown
Contributor

Lash-L commented Oct 20, 2025

Because of the drastic changes in how we are communicating, I think we should close out all connection based issues.

especially as these changes should help communication and recovery. Maybe you disagree, so lmk what you think

In my opinion these should be closed by this pr (some of these have had partial fixes in the past, but users have had connection issues and the issues have remained open)
#154476
#153351
#151099
#150862
#146887
#146428
#145445
#125169
#141664

Maybe:
#147427
#98013

allenporter added a commit to allenporter/home-assistant-core that referenced this pull request Oct 25, 2025
This is a breaking change that required these changes:
- Importing containers and data
- Changes to some dataclass computed values

This is also required for home-assistant#154837 which will switch to another API within the same library.
@allenporter allenporter mentioned this pull request Oct 25, 2025
21 tasks
@allenporter allenporter marked this pull request as ready for review October 28, 2025 14:44
Fix is cleaning

Update images

reorder setup functions

Revert coordinator and entity inheritance changes

Revert device changes

Revert some changes to reduce diffs

Revert changes in switch

Revert time entity changes

Update coordinator and fix image and select tests

Update to new import paths

Update to new import locations

Update image tests

Update binary sensor tests

Update clean summary and remove unnecessary waits

Make more init tests pass

Update sensor and select tests and many coordinator improvements

Use new diagnostics api

Fix unique device identifiers in tests

Remove _get_update_interval

Fix room sensor test

Update TODOs

Refresh status before attempting home discovery

Refresh all traits in coordinator

Update coordinator behavior to handle busy device

Add back partial failure behavior

Remove todo and replace with create_home_data_from_api_client

Reduce unnecessary diffs and improve failure handling

Remove async-timeout forbidden package
Comment thread homeassistant/components/roborock/button.py
Comment thread homeassistant/components/roborock/coordinator.py
Comment thread homeassistant/components/roborock/coordinator.py
Comment thread homeassistant/components/roborock/switch.py
@allenporter allenporter mentioned this pull request Nov 8, 2025
21 tasks
Comment thread homeassistant/components/roborock/__init__.py
Comment thread homeassistant/components/roborock/__init__.py Outdated
Comment thread homeassistant/components/roborock/button.py Outdated
Comment thread homeassistant/components/roborock/button.py
Comment thread homeassistant/components/roborock/coordinator.py Outdated
Comment thread homeassistant/components/roborock/coordinator.py Outdated
Comment thread homeassistant/components/roborock/image.py Outdated
Comment thread homeassistant/components/roborock/select.py Outdated
Comment thread tests/components/roborock/conftest.py Outdated
Comment thread homeassistant/components/roborock/coordinator.py Outdated
Comment thread homeassistant/components/roborock/switch.py
Copy link
Copy Markdown
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @allenporter 👍

Some small suggestions that can be discussed in follow ups/Discord.

@@ -341,3 +246,5 @@ async def async_unload_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
async def async_remove_entry(hass: HomeAssistant, entry: RoborockConfigEntry) -> None:
"""Handle removal of an entry."""
await async_remove_map_storage(hass, entry.entry_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we don't use the old format anymore, should we remove it in a config entry migration instead?
In my opinion, this would be cleaner, and we could even remove old data, as I don't expect that any current user will remove the config entry soon

return self._devices


def make_fake_switch(obj: Any) -> Any:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the Any here and in the other functions, as it makes it hard for others to know which functions/attributes the object should have


def create_v1_properties(network_info: NetworkInfo) -> Mock:
"""Create v1 properties for each fake device."""
v1_properties = Mock()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the spec to the specific object?

@edenhaus edenhaus merged commit ea651c4 into home-assistant:dev Nov 26, 2025
36 checks passed
@frenck frenck removed this from the 2025.12.0b0 milestone Nov 26, 2025
@allenporter allenporter mentioned this pull request Nov 26, 2025
21 tasks
@allenporter allenporter mentioned this pull request Nov 26, 2025
21 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.