feat: align Q10 map colors with V1 - #902
Conversation
allenporter
left a comment
There was a problem hiding this comment.
Looks good to me, just some small nits
| room_colors = adjacency_aware_room_colors(raw_data, width, self._room_palette, room_id) | ||
| for number, color in room_colors.items(): | ||
| self._room_palette.cached_room_colors[number] = color | ||
| self._room_palette.cached_room_colors[str(number)] = color |
There was a problem hiding this comment.
I dont see any code that uses strings for this. Can you explain what's going on here?
otherwise i think tis can be:
self._room_palette.cached_room_colors.update(room_colors)
There was a problem hiding this comment.
ColorsPalette.get_room_color accepts str | int and intentionally caches both key forms. Since the cache is pre-populated, updating only the integer entries would leave the corresponding string entries at their original colors, so get_room_color("12") could disagree with get_room_color(12) after recoloring. I kept both assignments, made the cache contract explicit in a comment, and added a regression assertion for the two key forms in e44a7ae.
| self._room_palette.cached_room_colors.clear() | ||
| self._room_palette.cached_room_colors.update(self._base_room_colors) |
There was a problem hiding this comment.
Does this work as a one-liner?
| self._room_palette.cached_room_colors.clear() | |
| self._room_palette.cached_room_colors.update(self._base_room_colors) | |
| self._room_palette.cached_room_colors = {**self._base_room_colors} |
There was a problem hiding this comment.
That one-liner does not work because cached_room_colors is a getter-only property; assigning to it raises AttributeError. The clear/update pair intentionally resets the existing dictionary in place. I introduced a local variable and added a comment in e44a7ae to make that constraint clearer.
There was a problem hiding this comment.
Ah ok. So we're mutating a property meant to be readonly. This seems to me like it is abusing this API, and not really whats intended by returning a readonly property.
I want to get this improvement in, but I don't think this is sustainable. We can discuss further in discord how we want to fix this.
Summary
First rendering slice extracted from #900. The Q10 base raster now follows the V1 map palette, including transparent out-of-map pixels, while both map formats share the same deterministic adjacent-room color policy.
Changes
Before / after
The same synthetic occupancy grid is rendered on
mainand on this branch.The checkerboard in the after image denotes transparency.
Validation
pytest -q— 882 passed, 86 snapshots passedpre-commit run --files ...— all hooks passedStack
The transport correction is independent in #901. #900 remains the aggregate real-device/Home Assistant before-and-after reference.