Skip to content

Implementing Materials detected from the Vacuums#41

Merged
sca075 merged 25 commits intomainfrom
dev_main
Jan 17, 2026
Merged

Implementing Materials detected from the Vacuums#41
sca075 merged 25 commits intomainfrom
dev_main

Conversation

@sca075
Copy link
Owner

@sca075 sca075 commented Jan 13, 2026

  • Material class development.
  • Insert in drawable elements materials to enable and disable them.

Summary by CodeRabbit

  • New Features

    • Carpet zones are now supported and visible in map visualizations.
    • Material overlays for wood and tile textures can be rendered on map segments with configurable colors/opacity.
    • Polygon map entities are supported for richer map shapes.
    • Per-segment material tracking enables material-aware rendering.
  • Chores

    • Package version updated to 0.1.17.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box>
Signed-off-by: Sandro Cantarella <sandro@79f3d049-9006-400d-9954-2e5dcd250fa9.fritz.box>
Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
…it bump version in pyproject.toml added to __init__.py Trims and Floor Data

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
…ses old key trims_data

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
- Add CARPET drawable element with configurable color and alpha
- Implement carpet zone parsing from Valetudo JSON (PolygonMapEntity)
- Add carpet rendering with customizable color (default: 50% of room_0)
- Support disable_carpets flag to toggle carpet visibility
- Fix COLORS list order to match base_color_keys mapping
- Fix floor rendering to use correct MAP_BACKGROUND color
- Add carpet color configuration to device_info

Fixes color index mismatch that affected carpet and floor color updates

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
from_list

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Fixes carpet color/alpha from device_info not being applied due to
missing DrawableElement.CARPET entry in update_from_device_info().

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
…tial implementation attempt and is not needed since we're using the simpler approach of passing color_carpet directly from device_info to the zones() drawing method.

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
@sca075 sca075 self-assigned this Jan 13, 2026
@sca075 sca075 added the enhancement New feature or request label Jan 13, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Warning

Rate limit exceeded

@sca075 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b009533 and f30bafd.

📒 Files selected for processing (2)
  • SCR/valetudo_map_parser/config/material.py
  • SCR/valetudo_map_parser/hypfer_draw.py
📝 Walkthrough

Walkthrough

This PR adds carpet and per-segment material support: new color/constants for carpet/wood/tile, a MaterialTileRenderer to generate textures, propagation of segment material metadata through map parsing, and drawing logic to composite material overlays and draw carpet zones.

Changes

Cohort / File(s) Summary
Color System Configuration
SCR/valetudo_map_parser/config/colors.py
Added SupportedColor members for OBSTACLE, TILE, WOOD; introduced color_material_wood, color_material_tile; extended COLORS_RGB, base_colors_array, color_array; updated set_initial_colours to initialize material colors and alphas.
Drawable Elements
SCR/valetudo_map_parser/config/drawable_elements.py
Added DrawableElement.MATERIAL_OVERLAY = 13; added default properties and z-index for MATERIAL_OVERLAY; extended update_from_device_info to read color_material_wood, alpha_material_wood, color_material_tile, alpha_material_tile and a disable_material_overlay flag.
Material Rendering Engine
SCR/valetudo_map_parser/config/material.py
New module: MaterialTileRenderer with get_tile, tile_block, apply_overlay_on_region; internal helpers for wood (horizontal/vertical) and tile pattern rendering; caching and safe overlay application.
Constants
SCR/valetudo_map_parser/const.py
Added COLOR_CARPET, COLOR_MATERIAL_WOOD, COLOR_MATERIAL_TILE and corresponding ALPHA_* constants; extended DEFAULT_VALUES with carpet/material color & alpha entries; trims_data restructured to a nested dict.
Shared Configuration
SCR/valetudo_map_parser/config/shared.py
Removed CONF_SNAPSHOTS_ENABLE from public imports; only formatting adjustments otherwise.
Drawing Core Integration
SCR/valetudo_map_parser/hypfer_draw.py
Added _apply_material_overlay to composite material tiles onto segment pixels; async_draw_zones now accepts color_carpet parameter; _process_room_layer applies material overlays for segment layers (when enabled and material present) and draws carpet zones when applicable.
Drawing Handler
SCR/valetudo_map_parser/hypfer_handler.py
Passes carpet color into async_draw_zones from _draw_dynamic_elements; minor comment update regarding floor layers.
Map Data Structures
SCR/valetudo_map_parser/map_data.py
Added PolygonMeta and PolygonMapEntity typed dicts and included in Entity union; extended SegmentMeta with material; threaded materials_dict through find_layers; HyperMapData gains materials and is populated in async_from_valetudo_json.
Handler Import Reordering
SCR/valetudo_map_parser/rand256_handler.py
Minor import reorder (moved COLORS/DEFAULT_* imports after initialize_drawing_config); no behavior change.
Version Bump
pyproject.toml
Package version updated from 0.1.15 to 0.1.17.

Sequence Diagram(s)

sequenceDiagram
    participant MapProcessor as MapProcessor (map_data)
    participant ImageDraw as ImageDraw (hypfer_draw)
    participant MaterialRenderer as MaterialTileRenderer (config/material)
    participant ImageArray as Image Array (RGBA)

    MapProcessor->>ImageDraw: pass materials_dict per segment
    ImageDraw->>ImageDraw: for each segment, check MATERIAL_OVERLAY enabled & material present
    alt material overlay applicable
        ImageDraw->>MaterialRenderer: get_tile(material, pixel_size, wood_rgba, tile_rgba)
        MaterialRenderer-->>ImageDraw: return tile (cached)
        ImageDraw->>MaterialRenderer: tile_block(tile, r0, r1, c0, c1)
        MaterialRenderer-->>ImageDraw: return tile region
        ImageDraw->>MaterialRenderer: apply_overlay_on_region(image, tile_region, r0, r1, c0, c1)
        MaterialRenderer->>ImageArray: composite tile onto image using alpha
    end
    ImageDraw->>ImageDraw: draw carpet zones if enabled using color_carpet
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 I hop in code through pixel miles,

Carpets, tiles and wooden tiles,
I paint each room with patterned cheer,
Nibble bugs and patch each peer,
Hooray — the map grows bright and styled.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Implementing Materials detected from the Vacuums' directly aligns with the PR's main objective of adding material detection and rendering capabilities. It accurately summarizes the primary feature being introduced.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
@sca075 sca075 marked this pull request as ready for review January 16, 2026 22:22
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
SCR/valetudo_map_parser/const.py (1)

36-47: Critical: COLORS list order does not match SupportedColor enum order, breaking color rendering.

The handlers map COLORS by enumeration index to user_colors, but user_colors is built by iterating SupportedColor in enum definition order. These orderings are completely different:

  • colors["wall"] maps to user_colors[0] which is CHARGER color (not WALLS)
  • colors["zone_clean"] maps to user_colors[1] which is PATH color (not ZONE_CLEAN)
  • And so on for all 10 entries in COLORS

Every rendered map element will display the wrong color. The COLORS list must be reordered to match the SupportedColor enum iteration order (excluding room colors), or the indexing logic in handlers must be updated to use SupportedColor keys directly instead of positional COLORS enumeration.

Note: Direct access to user_colors[10] and user_colors[11] in hypfer_draw.py for materials is correct and unaffected.

SCR/valetudo_map_parser/map_data.py (1)

872-899: materials field missing from update_from_dict allowed set.

The materials field was added to HyperMapData and is handled in from_dict, but update_from_dict doesn't include it in the allowed set. This means partial updates won't be able to modify materials.

🔧 Proposed fix
         allowed = {
             "json_data",
             "json_id",
             "obstacles",
             "paths",
             "image_size",
             "areas",
             "pixel_size",
             "entity_dict",
             "layers",
             "active_zones",
             "virtual_walls",
+            "materials",
         }
🤖 Fix all issues with AI agents
In `@SCR/valetudo_map_parser/config/drawable_elements.py`:
- Around line 232-256: The property-update block in drawable_elements.py uses
mismatched dict keys so values never get set; inside the block that calls
DrawableElement.set_property (reference set_property and
DrawableElement.MATERIAL_OVERLAY), replace the incorrect lookups
device_info["alpha_material_wood"], device_info["color_material_tile"], and
device_info["alpha_material_tile"] with the matching keys used in the condition
checks: device_info["material_wood_alpha"], device_info["material_tile_color"],
and device_info["material_tile_alpha"] respectively so the
material_wood_alpha/material_tile_color/material_tile_alpha values are read and
applied correctly.
🧹 Nitpick comments (3)
SCR/valetudo_map_parser/config/colors.py (1)

137-152: Comments in color_array may be misleading.

The comments for indices 8 and 9 (color_predicted_path and color_obstacle) don't seem to match the actual array values being referenced from base_colors_array. Index 8 is base_colors_array[8] which is color_charger, and index 9 is base_colors_array[9] which is color_no_go.

Suggestion: Fix misleading comments
 color_array = [
     base_colors_array[0],  # color_wall
     base_colors_array[6],  # color_no_go
     base_colors_array[7],  # color_go_to
-    base_colors_array[8],  # color_predicted_path
-    base_colors_array[9],  # color_obstacle
+    base_colors_array[8],  # color_charger
+    base_colors_array[9],  # color_no_go
     color_black,
SCR/valetudo_map_parser/config/material.py (1)

14-29: Unused singleton _material_colors.

MaterialColors dataclass and _material_colors singleton are defined but never referenced. The code directly uses color_material_wood and color_material_tile imports instead.

Consider removing the unused code or utilizing the singleton for consistency:

-@dataclass(frozen=True, slots=True)
-class MaterialColors:
-    """Material colors for rendering."""
-
-    wood_rgba: Color = color_material_wood
-    tile_rgba: Color = color_material_tile
-
-
-# Create a singleton instance for easy access
-_material_colors = MaterialColors()
SCR/valetudo_map_parser/hypfer_draw.py (1)

121-148: Replace magic indices with named constants for material colors.

Hardcoded indices 10 and 11 are correct now, but this coupling to array positions in user_colors is fragile. Named constants COLOR_MATERIAL_WOOD and COLOR_MATERIAL_TILE are already defined in const.py and should be used for explicit lookup instead, making the code resilient to reordering of base_color_keys in colors.py.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
SCR/valetudo_map_parser/config/colors.py (2)

10-69: Duplicate imports will cause a syntax error.

ALPHA_CARPET is imported twice (lines 12 and 14), and COLOR_CARPET is imported twice (lines 41 and 43). This will cause Python to raise a SyntaxError at import time.

🐛 Proposed fix to remove duplicate imports
 from ..const import (
     ALPHA_BACKGROUND,
     ALPHA_CARPET,
     ALPHA_CHARGER,
-    ALPHA_CARPET,
     ALPHA_GO_TO,
     ALPHA_MATERIAL_TILE,
     ALPHA_MATERIAL_WOOD,
     ALPHA_MOVE,
     ALPHA_NO_GO,
     ALPHA_ROBOT,
     ALPHA_ROOM_0,
     ALPHA_ROOM_1,
     ALPHA_ROOM_2,
     ALPHA_ROOM_3,
     ALPHA_ROOM_4,
     ALPHA_ROOM_5,
     ALPHA_ROOM_6,
     ALPHA_ROOM_7,
     ALPHA_ROOM_8,
     ALPHA_ROOM_9,
     ALPHA_ROOM_10,
     ALPHA_ROOM_11,
     ALPHA_ROOM_12,
     ALPHA_ROOM_13,
     ALPHA_ROOM_14,
     ALPHA_ROOM_15,
     ALPHA_TEXT,
     ALPHA_WALL,
     ALPHA_ZONE_CLEAN,
     COLOR_BACKGROUND,
     COLOR_CARPET,
     COLOR_CHARGER,
-    COLOR_CARPET,
     COLOR_GO_TO,
     COLOR_MATERIAL_TILE,
     COLOR_MATERIAL_WOOD,

139-154: Critical index mismatch in color_array after adding new colors to base_colors_array.

Adding color_carpet, color_material_wood, and color_material_tile at indices 2-4 shifted all subsequent elements, but the indices in color_array were not updated. The comments reveal the intended colors, but the actual indices now point to wrong colors:

Index Comment says Actually resolves to
[6] color_no_go color_background
[7] color_go_to color_move
[8] color_predicted_path color_charger
[9] color_obstacle color_no_go
[2] color_robot color_carpet
[5] color_charger color_robot
[4] color_move color_material_tile
[3] color_background color_material_wood
🐛 Proposed fix to correct indices based on comments
 color_array = [
     base_colors_array[0],  # color_wall
-    base_colors_array[6],  # color_no_go
-    base_colors_array[7],  # color_go_to
-    base_colors_array[8],  # color_predicted_path
-    base_colors_array[9],  # color_obstacle
+    base_colors_array[9],  # color_no_go
+    base_colors_array[10],  # color_go_to
+    color_grey,  # color_predicted_path (not in base_colors_array)
+    color_no_go,  # color_obstacle (use direct reference)
     color_black,
-    base_colors_array[2],  # color_robot
-    base_colors_array[5],  # color_charger
+    base_colors_array[5],  # color_robot
+    base_colors_array[8],  # color_charger
     color_text,
-    base_colors_array[4],  # color_move
-    base_colors_array[3],  # color_background
+    base_colors_array[7],  # color_move
+    base_colors_array[6],  # color_background
     base_colors_array[1],  # color_zone_clean
     color_transparent,
     rooms_color,
 ]

Alternatively, consider using direct color variable references instead of array indices to avoid this fragility:

color_array = [
    color_wall,
    color_no_go,
    color_go_to,
    # ... etc
]

Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
Signed-off-by: SCA075 <82227818+sca075@users.noreply.github.com>
@sca075 sca075 merged commit 652e8f7 into main Jan 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant