From 9c372d04e59c189f057cfaacbf3ccca1eecb8b0b Mon Sep 17 00:00:00 2001 From: Kris Anderson <1562427+kris-anderson@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:43:55 -0800 Subject: [PATCH] fix(rooms): let a name that differs only in case update the room's spelling upsert_inventory_room matches an existing room ignoring case so a room isn't created twice, but it returned and kept the stored spelling, so a rename that only changes capitals came back unchanged. Store the new spelling on the matched room; its id and created=false stay the same. Co-Authored-By: Claude Opus 5.5 --- .../https_server/routes/user/homes/service.py | 6 +++- tests/test_admin_api.py | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/roborock_local_server/bundled_backend/https_server/routes/user/homes/service.py b/src/roborock_local_server/bundled_backend/https_server/routes/user/homes/service.py index 547fa73..c34e8a9 100644 --- a/src/roborock_local_server/bundled_backend/https_server/routes/user/homes/service.py +++ b/src/roborock_local_server/bundled_backend/https_server/routes/user/homes/service.py @@ -59,7 +59,11 @@ def upsert_inventory_room(ctx: ServerContext, *, home_id: int, room_name: str) - None, ) if existing_room is not None: - room_payload = {"id": as_int(existing_room.get("id"), 0), "name": str(existing_room.get("name") or normalized_name)} + # The match ignores case so a room isn't created twice. A name that differs only in case + # is a correction to that room's spelling, so store it; otherwise the first spelling could + # never be changed, since nothing else renames a room. + existing_room["name"] = normalized_name + room_payload = {"id": as_int(existing_room.get("id"), 0), "name": normalized_name} created = False else: next_room_id = max((as_int(room.get("id"), 0) for room in rooms if isinstance(room, dict)), default=0) + 1 diff --git a/tests/test_admin_api.py b/tests/test_admin_api.py index 13341a3..9f0fd4c 100644 --- a/tests/test_admin_api.py +++ b/tests/test_admin_api.py @@ -1602,3 +1602,36 @@ def test_create_room_returns_bare_id_in_result_and_object_in_data(tmp_path: Path assert body["data"]["id"] == body["result"] assert body["data"]["name"] == "Study" assert body["data"]["created"] is True + + +def test_create_room_with_new_capitalization_updates_existing_room(tmp_path: Path) -> None: + config_file = write_release_config(tmp_path) + config = load_config(config_file) + paths = resolve_paths(config_file, config) + paths.inventory_path.parent.mkdir(parents=True, exist_ok=True) + rooms = [{"id": 11100, "name": "Master bedroom"}, {"id": 11101, "name": "Hallway"}] + paths.inventory_path.write_text( + json.dumps({"home": {"id": 1316433, "name": "My Home", "rooms": rooms}, "rooms": rooms}) + "\n", + encoding="utf-8", + ) + _seed_protocol_snapshot(paths.cloud_snapshot_path) + + supervisor = ReleaseSupervisor(config=config, paths=paths) + client = TestClient(supervisor.app) + + path = "/user/homes/1316433/rooms" + response = client.post( + path, + data={"name": "Master Bedroom"}, + headers=_hawk_headers(paths.cloud_snapshot_path, path, form_values={"name": "Master Bedroom"}), + ) + + assert response.status_code == 200 + body = response.json() + assert body["result"] == 11100 + assert body["data"]["name"] == "Master Bedroom" + assert body["data"]["created"] is False + + stored_inventory = json.loads(paths.inventory_path.read_text(encoding="utf-8")) + for stored_rooms in (stored_inventory["home"]["rooms"], stored_inventory["rooms"]): + assert stored_rooms == [{"id": 11100, "name": "Master Bedroom"}, {"id": 11101, "name": "Hallway"}]