Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/roborock/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ def __init__(
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

]

async def _async_update_data(
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/roborock/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ def _dock_error_value_fn(state: DeviceState) -> str | None:
translation_key="main_brush_time_left",
entity_category=EntityCategory.DIAGNOSTIC,
),
RoborockSensorDescriptionB01(
key="battery",
value_fn=lambda data: data.battery,

Copilot AI Mar 23, 2026

Copy link

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.
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
),
Comment thread
lboue marked this conversation as resolved.
Comment on lines +369 to +375
Comment on lines +369 to +375

Copilot AI Mar 23, 2026

Copy link

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.
Comment on lines +369 to +375

Copilot AI Mar 23, 2026

Copy link

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(
Comment on lines +369 to 376

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

key="side_brush_time_left",
value_fn=lambda data: data.side_brush_time_left,
Expand Down
1 change: 1 addition & 0 deletions tests/components/roborock/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@
main_sensor=500,
mop_life=1200,
real_clean_time=3000,
quantity=100,
)

Q10_STATUS = Q10Status(
Expand Down
52 changes: 52 additions & 0 deletions tests/components/roborock/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,58 @@
'state': '3.55',
})
# ---
# name: test_sensors[sensor.roborock_q7_battery-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.roborock_q7_battery',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Battery',
'options': dict({
}),
'original_device_class': <SensorDeviceClass.BATTERY: 'battery'>,
'original_icon': None,
'original_name': 'Battery',
'platform': 'roborock',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'battery_q7_duid',
'unit_of_measurement': '%',
})
# ---
# name: test_sensors[sensor.roborock_q7_battery-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'battery',
'friendly_name': 'Roborock Q7 Battery',
'unit_of_measurement': '%',
}),
'context': <ANY>,
'entity_id': 'sensor.roborock_q7_battery',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '100',
})
# ---
# name: test_sensors[sensor.roborock_q7_filter_time_left-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down
Loading