Skip to content

Battery status for Roborock Q7#165886

Merged
joostlek merged 9 commits intohome-assistant:devfrom
RaddedMC:roborock_q7_battery_status
Mar 24, 2026
Merged

Battery status for Roborock Q7#165886
joostlek merged 9 commits intohome-assistant:devfrom
RaddedMC:roborock_q7_battery_status

Conversation

@RaddedMC
Copy link
Copy Markdown
Contributor

Proposed change

Update the Roborock integration to view battery level for Q7 family devices.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

@RaddedMC RaddedMC requested a review from allenporter as a code owner March 18, 2026 07:30
Copilot AI review requested due to automatic review settings March 18, 2026 07:30
Copy link
Copy Markdown

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @RaddedMC

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot added the small-pr PRs with less than 30 lines. label Mar 18, 2026
@home-assistant
Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft March 18, 2026 07:30
@home-assistant
Copy link
Copy Markdown

Hey there @Lash-L, @allenporter, 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, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) 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 extends the Roborock integration’s B01/Q7 support to expose the device battery level as a Home Assistant sensor.

Changes:

  • Add a new Q7 (B01) battery sensor entity description (battery_level) backed by the B01 props payload.
  • Include RoborockB01Props.QUANTITY in the Q7 coordinator’s requested protocols so the battery value is available.

Reviewed changes

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

File Description
homeassistant/components/roborock/sensor.py Adds a new Q7 B01 battery sensor entity description using data.quantity.
homeassistant/components/roborock/coordinator.py Requests the additional B01 property (QUANTITY) needed to populate the new sensor.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread homeassistant/components/roborock/sensor.py Outdated
Comment thread homeassistant/components/roborock/sensor.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 07:36
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

Adds battery level reporting for Roborock Q7-family (B01) devices by requesting the additional property from the device and exposing it as a Sensor entity.

Changes:

  • Add a new Q7 (B01) battery percentage sensor based on the quantity property.
  • Extend the Q7 B01 coordinator’s requested properties to include RoborockB01Props.QUANTITY.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
homeassistant/components/roborock/sensor.py Introduces a new Q7 B01 battery sensor entity description.
homeassistant/components/roborock/coordinator.py Requests the extra B01 property needed to populate the new battery sensor.

You can also share your feedback on Copilot code review. Take the survey.

value_fn=lambda data: data.quantity,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
suggested_unit_of_measurement=PERCENTAGE,
Comment on lines +369 to +376
RoborockSensorDescriptionB01(
key="battery_level",
value_fn=lambda data: data.quantity,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
suggested_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
Comment thread homeassistant/components/roborock/sensor.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 07:43
Removed suggested unit of measurement for battery sensor.
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

Adds battery level reporting for Roborock Q7-family (B01) devices by requesting and exposing the appropriate property through the Roborock integration.

Changes:

  • Add a new Q7 B01 battery sensor entity (percent).
  • Extend the Q7 B01 coordinator’s requested property list to include the battery/quantity protocol.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/roborock/sensor.py Adds a Q7 B01 battery sensor based on B01Props.quantity.
homeassistant/components/roborock/coordinator.py Requests RoborockB01Props.QUANTITY so the battery value is available to entities.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +369 to 376
RoborockSensorDescriptionB01(
key="battery",
value_fn=lambda data: data.quantity,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescriptionB01(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

@Lash-L Lash-L left a comment

Choose a reason for hiding this comment

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

Hey @RaddedMC - let me know how I can help you out here! I believe you said this was your first contribution, so let me know if there is anyway I can help you out or any questions I can answer. I want to make sure you don't get overwhelmed!

So you know, the beta cutoff is on Wednesday(early in the day typically). If you are hoping to get this included in 2026.4, we should aim to get this reviewed and merged by then!

RoborockB01Props.WIND,
RoborockB01Props.WATER,
RoborockB01Props.MODE,
RoborockB01Props.QUANTITY,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this isn't needed right? You can just access the .battery property directly from the B01Props object

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this isn't needed right? You can just access the .battery property directly from the B01Props object

I updated python-roborock to the latest (5.0.0) version and tried changing it to battery and got the below error.

2026-03-23 22:57:34.650 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry mycooljames@hotmail.com for roborock
Traceback (most recent call last):
  File "/workspaces/home-assistant-core/homeassistant/config_entries.py", line 769, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/homeassistant/components/roborock/__init__.py", line 149, in async_setup_entry
    *build_setup_functions(hass, entry, enabled_devices, user_data),
     ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/home-assistant-core/homeassistant/components/roborock/__init__.py", line 281, in build_setup_functions
    RoborockB01Q7UpdateCoordinator(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        hass, entry, device, device.b01_q7_properties
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/workspaces/home-assistant-core/homeassistant/components/roborock/coordinator.py", line 550, in __init__
    RoborockB01Props.BATTERY,
    ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'RoborockB01Props' has no attribute 'BATTERY'

I think because we agreed to make it an @Property instead of an enum class, this .QUANTITY is there to tell the API to reply back with the quantity value that we need in order to get the battery level.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yes that makes sense

@RaddedMC
Copy link
Copy Markdown
Contributor Author

Hey thanks you for reaching out. I've been a bit busy this past week but I'll aim to work on it for the weekend.

I made some changes before I finished my pull to the Python Roborock repo so there are some unnecessary components that reference "quantity" instead of "battery" that I need to fix.

I wasn't aware of the release schedule so thanks for letting me know!

Copilot AI review requested due to automatic review settings March 23, 2026 23:05
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

Adds battery level reporting for Roborock Q7-family (B01) devices by exposing the battery value as a Sensor entity and ensuring the coordinator requests the needed property from the device API.

Changes:

  • Add a new Q7 B01 battery sensor description (SensorDeviceClass.BATTERY, %).
  • Update the Q7 B01 coordinator request protocols to include the property needed to retrieve battery.
  • Extend Q7 B01 test mock props with a representative battery value.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/roborock/sensor.py Adds a Q7 B01 battery sensor entity definition.
homeassistant/components/roborock/coordinator.py Requests an additional B01 property so battery data is available during updates.
tests/components/roborock/mock_data.py Provides battery=100 in Q7 B01 mock props so the new sensor is created during tests.

Comment on lines +369 to +375
RoborockSensorDescriptionB01(
key="battery",
value_fn=lambda data: data.battery,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The Q7 B01 battery sensor adds a new entity that will be included by tests/components/roborock/test_sensor.py’s snapshot-based coverage. Since tests/components/roborock/snapshots/test_sensor.ambr currently has no sensor.roborock_q7_battery entry, the existing snapshot test will fail (and the new entity isn’t validated) until the snapshot is updated to include this new sensor (entry + state).

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 23, 2026 23:29
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +369 to +375
RoborockSensorDescriptionB01(
key="battery",
value_fn=lambda data: data.battery,
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Update the Roborock sensor snapshot to include the new Q7 battery entity so the existing snapshot tests stay in sync.

Copilot uses AI. Check for mistakes.
),
RoborockSensorDescriptionB01(
key="battery",
value_fn=lambda data: data.battery,
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Align the Q7 battery sensor’s value source with the B01 property being requested (QUANTITY), e.g., use the corresponding B01Props field/accessor or document the alias, to avoid relying on a potentially non-existent B01Props.battery attribute.

Suggested change
value_fn=lambda data: data.battery,
value_fn=lambda data: data.quantity.battery,

Copilot uses AI. Check for mistakes.
@RaddedMC RaddedMC marked this pull request as ready for review March 23, 2026 23:43
Copilot AI review requested due to automatic review settings March 23, 2026 23:43
@home-assistant home-assistant bot requested a review from Lash-L March 23, 2026 23:43
@RaddedMC
Copy link
Copy Markdown
Contributor Author

Okay looks like I finally got all the tests to pass!

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@joostlek joostlek merged commit 035e004 into home-assistant:dev Mar 24, 2026
36 of 37 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants