Skip to content

Conversation

@sca075
Copy link
Owner

@sca075 sca075 commented Oct 2, 2025

Some safe guard in shared and parser improvement for rand.

…ean tested for rand.

Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box>
@sca075 sca075 self-assigned this Oct 2, 2025
@sca075 sca075 changed the title dev Rand256 Paser Zones and Share data Oct 2, 2025
@sca075 sca075 requested a review from Copilot October 2, 2025 20:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds zone/area parsing for Rand256 maps, centralizes logging through a shared LOGGER, and revises shared state serialization and destination typing. Key changes include new parser helpers for currently cleaned and forbidden zones, alterations to how shared image data is exposed, and a type update for Destinations.updated.

  • Added _parse_area and _parse_zones plus integration into block parsing and final JSON assembly.
  • Reworked shared data export (to_dict) and attributes (added image_last_updated/content_type; removed several image metadata fields).
  • Centralized logging by removing module-level loggers and importing LOGGER from types.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pyproject.toml Bumps version to 0.1.10rc7.
reimg_draw.py Replaces local logger with shared LOGGER.
rand256_handler.py Moves zone/point assignments into shared state; logging adjustments.
config/utils.py Adjusts room attribute unpacking and formatting; calibration and resize refactor.
config/types.py Adds new constants, changes Destinations.updated to float, adds parsing-related metadata/comment.
config/shared.py Alters attribute generation and image serialization structure (removes prior metadata fields, adds new ones).
config/rand256_parser.py Adds parsing logic for cleaned zones and forbidden zones and integrates them into parsed map output.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"format": self.image_format,
"updated": self.image_last_updated,
"pil_image": self.new_image,
"size": self.new_image.size if self.new_image else (10, 10),
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

Returning a fabricated default size (10, 10) when no image exists is misleading compared to the previous None behavior; this can cause downstream logic to treat an absent image as valid. Replace (10, 10) with None (or omit the key) when self.new_image is falsy.

Suggested change
"size": self.new_image.size if self.new_image else (10, 10),
"size": self.new_image.size if self.new_image else None,

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

image size can not be a none value in home assistant so this 10, 10 is just for testing this will be then covrt to 0,0 as soon I confirm this.

zones: NotRequired[Optional[List[Zone]]]
rooms: NotRequired[Optional[List[Room]]]
updated: NotRequired[Optional[int]]
updated: NotRequired[Optional[float]]
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

[nitpick] Changed updated type from Optional[int] to Optional[float]; if external consumers rely on integer (e.g., epoch seconds), this is a silent breaking change. Consider accepting both (Union[int, float]) or documenting the change and providing a migration path.

Suggested change
updated: NotRequired[Optional[float]]
updated: NotRequired[Optional[Union[int, float]]]

Copilot uses AI. Check for mistakes.
id: int


# list[dict[str, str | list[int]]] | list[dict[str, str | list[list[int]]]] | list[dict[str, str | int]] | int]'
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

This comment is unclear, contains mismatched brackets/quotes, and does not explain its purpose. Clarify the intent (e.g., describe an expected heterogeneous structure) or remove it to reduce noise.

Suggested change
# list[dict[str, str | list[int]]] | list[dict[str, str | list[list[int]]]] | list[dict[str, str | int]] | int]'

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

this comment line is the correct type of destinations and will need to work the type model later on on this base

sca075 added 2 commits October 3, 2025 14:23
Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box>
Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box>
@sca075 sca075 requested a review from Copilot October 3, 2025 12:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 108 to +115
self.shared.map_rooms = room_ids

# get the zones and points data
zone_properties = await self.async_zone_propriety(zones_data)
self.shared.map_pred_zones = await self.async_zone_propriety(zones_data)
# get the points data
point_properties = await self.async_points_propriety(points_data)
self.shared.map_pred_points = await self.async_points_propriety(points_data)

if not (room_properties or zone_properties):
if not (room_properties or self.shared.map_pred_zones):
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The function previously returned a tuple of (room_properties, zone_properties, point_properties); it now returns only room_properties but external code (see utils.py line 202) still performs tuple unpacking, causing a ValueError when multiple room ids exist. Either wrap the return as (room_properties,) and adjust callers to not expect zones/points, or revert to returning all three values consistently (preferred for clarity).

Copilot uses AI. Check for mistakes.

rooms = RoomStore(self.file_name, room_properties)
return room_properties, zone_properties, point_properties
return room_properties
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The function previously returned a tuple of (room_properties, zone_properties, point_properties); it now returns only room_properties but external code (see utils.py line 202) still performs tuple unpacking, causing a ValueError when multiple room ids exist. Either wrap the return as (room_properties,) and adjust callers to not expect zones/points, or revert to returning all three values consistently (preferred for clarity).

Suggested change
return room_properties
return room_properties, self.shared.map_pred_zones, self.shared.map_pred_points

Copilot uses AI. Check for mistakes.
self.shared.map_pred_zones,
self.shared.map_pred_points,
) = await self.get_rooms_attributes(destinations)
(self.shared.map_rooms,) = await self.get_rooms_attributes(destinations)
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

This single‑element tuple unpacking will iterate over the return value; since get_rooms_attributes now returns a dict (room_properties), this will raise ValueError unless the dict has exactly one key. Replace with direct assignment: self.shared.map_rooms = await self.get_rooms_attributes(destinations) or restore the original multi-value return contract.

Suggested change
(self.shared.map_rooms,) = await self.get_rooms_attributes(destinations)
self.shared.map_rooms = await self.get_rooms_attributes(destinations)

Copilot uses AI. Check for mistakes.
def get_rrm_forbidden_zones(json_data: JsonType) -> dict:
def get_rrm_forbidden_zones(json_data: JsonType) -> list[dict[str, Any]]:
"""Get the forbidden zones from the json."""
re_zones = json_data.get("forbidden_zones", [])
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

re_zones references the list object inside json_data and extend mutates the original JSON, causing forbidden_mop_zones to be appended permanently and potentially duplicated on subsequent calls. Use a copy to avoid side effects: re_zones = list(json_data.get("forbidden_zones", [])); then extend.

Suggested change
re_zones = json_data.get("forbidden_zones", [])
re_zones = list(json_data.get("forbidden_zones", []))

Copilot uses AI. Check for mistakes.
@sca075 sca075 merged commit 3bfa659 into main Oct 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants