fix(rooms): use the app's own RoomType→name strings; drop per-model overrides (#22)#48
fix(rooms): use the app's own RoomType→name strings; drop per-model overrides (#22)#48jgus wants to merge 2 commits into
Conversation
…verrides (sjmotew#22) The base ROOM_TYPE_NAMES was mis-derived (shifted from index 5 on: 5→Study, 8→Corridor, 11→Cloak Room…), so unnamed rooms got the wrong type label, and a per-product_key override map had been added to paper over it. Reverse-engineering the app shows there is nothing to override — room-type naming is model-independent: - map_engine_i18n_configer.roomTypei18nKey(int) is a single switch keyed only on the RoomType enum (MapBaseType.RoomType, 16 constants); it takes no product_key/model/device argument and reads no instance state. - It returns map_room_name_* keys resolved through one shared en-US.json in the app_res_config package — not per-model. - Live Flow 2 data matched the mapping (values 3/4/8/11: Living room, Kitchen, Dining room, Study). Adopt the app's exact en-US.json strings (e.g. "Living room", "Closet", "Kids' room", "Entertainment room", "Storage room", "Others"), remove the MODEL_ROOM_TYPE_OVERRIDES / model_key plumbing and the get_map product_key pass, and fix the stale RoomInfo field-2 docstring (it still listed the old wrong enum). Tests assert the verbatim names (including values that were previously paraphrased); both client copies updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Greptile SummaryThis PR fixes incorrect room-type labels for unnamed rooms by replacing the mis-derived
Confidence Score: 5/5Safe to merge — the change is a straightforward table correction backed by decompiled-app evidence and live device verification, with all 16 enum values now explicitly tested. The removal of the per-model override machinery is complete and consistent across both the library and embedded custom-component copies. The new ROOM_TYPE_NAMES table is a ClassVar with the verbatim app strings. All callers of from_response and display_name have been updated, no stale model_key references remain, and the rewritten tests cover every entry in the table including the four values that were previously wrong. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[NarwalClient.get_map] -->|send_command| B[resp.data]
B --> C[MapData.from_response\ndecoded]
C -->|for each room in field 2.12| D[RoomInfo\nroom_id, name, room_sub_type,\ncategory, instance_index]
D --> E{name set?}
E -->|yes| F[return name]
E -->|no| G[ROOM_TYPE_NAMES.get\nroom_sub_type, 'Room']
G --> H{instance_index > 1?}
H -->|yes| I[return 'BaseName N']
H -->|no| J[return 'BaseName']
Reviews (2): Last reviewed commit: "Feedback addressed" | Re-trigger Greptile |
Summary
Unnamed rooms were getting the wrong type label. The base
ROOM_TYPE_NAMEStablewas mis-derived (shifted from index 5 on —
5→Study,8→Corridor,11→Cloak Room…),and a per-
product_keyoverride map had been bolted on to patch it. This replacesboth with the app's own room-type names, verified by reverse-engineering the Narwal app.
Addresses #22.
Evidence (from the decompiled app)
Room-type naming in the app is model-independent — there is nothing to override:
MapEnginei18nConfiger.roomTypei18nKey(int)takes just the
RoomTypeint — noproduct_key/model/device/snargument, and itreads no instance state. It maps the enum to
map_room_name_*i18n keys.MapBaseType.RoomTypehas 16 constants; the switch handles them invalue order 0–15.
en-US.jsonin the app'sshared
app_res_configpackage — not per-model.(Living room, Kitchen, Dining room, Study).
The resulting table is taken verbatim from the app's
en-US.json:Changes
narwal_client/models.py(and the embeddedcustom_components/narwal/narwal_client/copy): set
ROOM_TYPE_NAMESto the verbatim app strings; removeMODEL_ROOM_TYPE_OVERRIDES,the
RoomInfo.model_keyfield, and the override lookup indisplay_name; drop the now-unusedproduct_keyparameter fromMapData.from_response; fix the staleRoomInfofield-2 docstring(it still listed the old, wrong enum).
narwal_client/client.py(and embedded copy):get_map()no longer computes/passes aproduct_keytofrom_response.tests/test_models.py: rewriteTestRoomInfoModelOverrides→TestRoomInfoNames(theoverride premise is gone); assert the verbatim names, including values that were previously
paraphrased.
tests/test_vacuum_segments.py: segment-name assertion updated (Toilet 2).Testing
pytest tests/— 166 passed.correct labels (Study, Dining room, …).
Footnote — localization (out of scope for this PR): the app ships these names in 23
locales, so the integration could later localize unnamed-room type labels to the user's Home
Assistant language. Some locales are untranslated stubs (e.g.
pt-BRships the keysempty), so such a follow-up would need an English fallback. User-assigned room names are
unaffected — they pass through as-is regardless of language.