Battery status for Roborock Q7#165886
Conversation
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @Lash-L, @allenporter, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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.QUANTITYin 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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
quantityproperty. - 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, |
| 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, | ||
| ), |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Removed suggested unit of measurement for battery sensor.
There was a problem hiding this comment.
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.
| RoborockSensorDescriptionB01( | ||
| key="battery", | ||
| value_fn=lambda data: data.quantity, | ||
| device_class=SensorDeviceClass.BATTERY, | ||
| native_unit_of_measurement=PERCENTAGE, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| ), | ||
| RoborockSensorDescriptionB01( |
There was a problem hiding this comment.
@copilot apply changes based on this feedback
Lash-L
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
this isn't needed right? You can just access the .battery property directly from the B01Props object
There was a problem hiding this comment.
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.
|
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! |
There was a problem hiding this comment.
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
batteryvalue.
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. |
| RoborockSensorDescriptionB01( | ||
| key="battery", | ||
| value_fn=lambda data: data.battery, | ||
| device_class=SensorDeviceClass.BATTERY, | ||
| native_unit_of_measurement=PERCENTAGE, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| ), |
There was a problem hiding this comment.
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).
| RoborockSensorDescriptionB01( | ||
| key="battery", | ||
| value_fn=lambda data: data.battery, | ||
| device_class=SensorDeviceClass.BATTERY, | ||
| native_unit_of_measurement=PERCENTAGE, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| ), |
There was a problem hiding this comment.
Update the Roborock sensor snapshot to include the new Q7 battery entity so the existing snapshot tests stay in sync.
| ), | ||
| RoborockSensorDescriptionB01( | ||
| key="battery", | ||
| value_fn=lambda data: data.battery, |
There was a problem hiding this comment.
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.
| value_fn=lambda data: data.battery, | |
| value_fn=lambda data: data.quantity.battery, |
|
Okay looks like I finally got all the tests to pass! |
Proposed change
Update the Roborock integration to view battery level for Q7 family devices.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.