Skip to content

feat: add shared rooms endpoint#826

Open
Lash-L wants to merge 3 commits intomainfrom
shared_rooms
Open

feat: add shared rooms endpoint#826
Lash-L wants to merge 3 commits intomainfrom
shared_rooms

Conversation

@Lash-L
Copy link
Copy Markdown
Collaborator

@Lash-L Lash-L commented May 4, 2026

relates to home-assistant/core#169639 (comment)

Add a new endpoint for getting shared room ids.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 90.42553% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
roborock/web_api.py 60.86% 5 Missing and 4 partials ⚠️
Files with missing lines Coverage Δ
roborock/devices/traits/v1/__init__.py 88.33% <100.00%> (ø)
roborock/devices/traits/v1/rooms.py 81.92% <100.00%> (+3.35%) ⬆️
tests/devices/traits/v1/fixtures.py 98.21% <100.00%> (+0.10%) ⬆️
tests/devices/traits/v1/test_rooms.py 98.27% <100.00%> (+0.18%) ⬆️
tests/test_web_api.py 100.00% <100.00%> (ø)
roborock/web_api.py 52.92% <60.86%> (+0.43%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 support for resolving room names for shared/received devices by introducing a dedicated web API endpoint and wiring it into the V1 Rooms trait logic (so shared devices don’t rely on the owner’s home room list).

Changes:

  • Add get_shared_device_rooms endpoint to the web API client (with response normalization for roomId vs id).
  • Update RoomsTrait to use shared-device rooms when the device is detected as shared, without mutating HomeData.rooms.
  • Add test coverage for the new endpoint and shared-device room name refresh behavior.

Reviewed changes

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

Show a summary per file
File Description
roborock/web_api.py Adds get_shared_device_rooms to RoborockApiClient and UserWebApiClient.
roborock/devices/traits/v1/rooms.py Uses shared-room lookup path for shared devices and maintains a separate shared room-name map.
roborock/devices/traits/v1/__init__.py Passes device_uid into RoomsTrait so it can detect shared devices.
tests/test_web_api.py Adds parametrized test for the new shared-device rooms endpoint payload variants.
tests/devices/traits/v1/test_rooms.py Adds test ensuring shared device room names come from get_shared_device_rooms and don’t mutate HomeData.rooms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread roborock/devices/traits/v1/rooms.py Outdated
Comment on lines +97 to +100
@cached_property
def _is_shared(self) -> bool:
return any(d.duid == self._device_uid for d in self._home_data.received_devices)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it's a pretty big edge case. It's very unlikely that shared devices changes mid run and we don't even really support that right now

But defer to your thoughts @allenporter

Copy link
Copy Markdown
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

Very nice work!

Comment thread roborock/devices/traits/v1/rooms.py Outdated

@cached_property
def _is_shared(self) -> bool:
return any(d.duid == self._device_uid for d in self._home_data.received_devices)
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.

We can check this up front in the constructor and if true, then set self._shared_device_uid then directly use that below when checking whether or not to check for shared device rooms

def _room_name_map(self) -> dict[str, str]:
return {**self._home_data.rooms_name_map, **self._shared_room_names}

async def refresh(self) -> None:
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.

The refresh_rooms method used to return all rooms such that we could overwrite the room list, but now it has a conditional to call a different API then we need to check that conditional again to correctly evaluate the room response type to know how to use it. I would say this could be improved to push the logic inside of refresh_rooms so that it always returns the final list of rooms.

Comment thread tests/devices/traits/v1/test_rooms.py Outdated
web_api_client.get_shared_device_rooms.assert_called_once_with(rooms_trait._device_uid)
web_api_client.get_rooms.assert_not_called()
finally:
rooms_trait._home_data.rooms = original_rooms
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.

do we need this try/finally for this test?

Comment thread tests/devices/traits/v1/test_rooms.py Outdated
try:
# Mark the device as shared by adding it to received_devices
device = next(d for d in rooms_trait._home_data.devices if d.duid == rooms_trait._device_uid)
rooms_trait._home_data.received_devices = [device]
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.

Instead of mutating internal state of the trait, add a new home data fixture input to device_fixture so that the test can build this up as input.

(Keep in mind there is other wiring like the product information etc that needs to be matched up)

Comment thread tests/devices/traits/v1/test_rooms.py Outdated
assert rooms_trait.rooms
assert rooms_trait.rooms[0] == NamedRoomMapping(segment_id=16, iot_id="2362048", raw_name="Example room 1")
assert rooms_trait.rooms[1] == NamedRoomMapping(segment_id=17, iot_id="9999999", raw_name="Office")
assert rooms_trait._home_data.rooms == original_rooms
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.

don't think we need to assert on this

Comment thread tests/devices/traits/v1/test_rooms.py Outdated
Comment on lines +233 to +235
assert rooms_trait.rooms
assert rooms_trait.rooms[0] == NamedRoomMapping(segment_id=16, iot_id="2362048", raw_name="Example room 1")
assert rooms_trait.rooms[1] == NamedRoomMapping(segment_id=17, iot_id="9999999", raw_name="Office")
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.

Worth asserting that there are two?

Suggested change
assert rooms_trait.rooms
assert rooms_trait.rooms[0] == NamedRoomMapping(segment_id=16, iot_id="2362048", raw_name="Example room 1")
assert rooms_trait.rooms[1] == NamedRoomMapping(segment_id=17, iot_id="9999999", raw_name="Office")
assert rooms_trait.rooms == [
NamedRoomMapping(segment_id=16, iot_id="2362048", raw_name="Example room 1"),
NamedRoomMapping(segment_id=17, iot_id="9999999", raw_name="Office"),
]

Comment thread tests/devices/traits/v1/test_rooms.py Outdated
room_mapping_data = [[16, "2362048"], [17, "9999999"]]
mock_rpc_channel.send_command.side_effect = [room_mapping_data]

await rooms_trait.refresh()
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.

worth asserting on the state before this is run? To verify these rooms weren't already set

@Lash-L Lash-L changed the title add shared rooms endpoint feat: add shared rooms endpoint May 4, 2026
@Lash-L Lash-L requested a review from allenporter May 4, 2026 14:18
@Lash-L
Copy link
Copy Markdown
Collaborator Author

Lash-L commented May 4, 2026

will fix commit lint on merge

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