Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions SCR/valetudo_map_parser/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ def get_rooms_count(self) -> int:
return count if count > 0 else DEFAULT_ROOMS
return DEFAULT_ROOMS

@property
def room_names(self) -> dict:
"""Return room names in format {'room_0_name': 'SegmentID: RoomName', ...}."""
result = {}
if isinstance(self.vacuums_data, dict):
for idx, (segment_id, room_data) in enumerate(self.vacuums_data.items()):
if idx >= 16: # Max 16 rooms
break
room_name = room_data.get("name", f"Room {segment_id}")
result[f"room_{idx}_name"] = f"{segment_id}: {room_name}"
Comment on lines +131 to +135
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add defensive check for room_data structure.

If room_data is not a dictionary (e.g., None, string, or other type), line 134 will raise an AttributeError when calling .get(). While the vacuums_data dict is expected to contain dict values, adding a defensive check improves robustness.

Apply this diff to add a type check:

         if isinstance(self.vacuums_data, dict):
             for idx, (segment_id, room_data) in enumerate(self.vacuums_data.items()):
                 if idx >= 16:  # Max 16 rooms
                     break
-                room_name = room_data.get("name", f"Room {segment_id}")
+                if isinstance(room_data, dict):
+                    room_name = room_data.get("name", f"Room {segment_id}")
+                else:
+                    room_name = f"Room {segment_id}"
                 result[f"room_{idx}_name"] = f"{segment_id}: {room_name}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for idx, (segment_id, room_data) in enumerate(self.vacuums_data.items()):
if idx >= 16: # Max 16 rooms
break
room_name = room_data.get("name", f"Room {segment_id}")
result[f"room_{idx}_name"] = f"{segment_id}: {room_name}"
if isinstance(self.vacuums_data, dict):
for idx, (segment_id, room_data) in enumerate(self.vacuums_data.items()):
if idx >= 16: # Max 16 rooms
break
if isinstance(room_data, dict):
room_name = room_data.get("name", f"Room {segment_id}")
else:
room_name = f"Room {segment_id}"
result[f"room_{idx}_name"] = f"{segment_id}: {room_name}"
🤖 Prompt for AI Agents
In SCR/valetudo_map_parser/config/types.py around lines 131 to 135, the loop
assumes room_data is a dict and calls room_data.get(...), which can raise
AttributeError if room_data is None or another type; add a defensive type check
(e.g., if not isinstance(room_data, dict) then treat room_name as a fallback
like str(room_data) or use a default name) before calling .get(), preserve the
existing early-break at 16 rooms, and ensure result[f"room_{idx}_name"] is
always assigned a safe string.

return result

@classmethod
def get_all_instances(cls) -> Dict[str, "RoomStore"]:
return cls._instances
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "valetudo-map-parser"
version = "0.1.11b1"
version = "0.1.11"
description = "A Python library to parse Valetudo map data returning a PIL Image object."
authors = ["Sandro Cantarella <gsca075@gmail.com>"]
license = "Apache-2.0"
Expand Down