valetudo-map-parser 0.1.9b27__py3-none-any.whl → 0.1.9b29__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,15 +25,20 @@ class TrimError(Exception):
25
25
  class AutoCrop:
26
26
  """Auto Crop Class for trimming and zooming images."""
27
27
 
28
- def __init__(self, image_handler):
28
+ def __init__(self, image_handler, shared):
29
29
  self.imh = image_handler
30
- self.file_name = self.imh.file_name
30
+ self.file_name = shared.file_name
31
+ self.shared = shared
31
32
 
32
- def validate_crop_dimensions(self, shared):
33
+ @staticmethod
34
+ def validate_crop_dimensions(shared):
33
35
  """Ensure width and height are valid before processing cropping."""
34
36
  if shared.image_ref_width <= 0 or shared.image_ref_height <= 0:
35
- _LOGGER.warning("Auto-crop failed: Invalid dimensions (width=%s, height=%s). Using original image.",
36
- shared.image_ref_width, shared.image_ref_height)
37
+ _LOGGER.warning(
38
+ "Auto-crop failed: Invalid dimensions (width=%s, height=%s). Using original image.",
39
+ shared.image_ref_width,
40
+ shared.image_ref_height,
41
+ )
37
42
  return False
38
43
  return True
39
44
 
@@ -65,18 +70,18 @@ class AutoCrop:
65
70
  ),
66
71
  )
67
72
  # Ensure shared reference dimensions are updated
68
- if hasattr(self.imh.shared, "image_ref_height") and hasattr(
69
- self.imh.shared, "image_ref_width"
73
+ if hasattr(self.shared, "image_ref_height") and hasattr(
74
+ self.shared, "image_ref_width"
70
75
  ):
71
- self.imh.shared.image_ref_height = trimmed_height
72
- self.imh.shared.image_ref_width = trimmed_width
76
+ self.shared.image_ref_height = trimmed_height
77
+ self.shared.image_ref_width = trimmed_width
73
78
  else:
74
79
  _LOGGER.warning(
75
80
  "Shared attributes for image dimensions are not initialized."
76
81
  )
77
82
  return trimmed_width, trimmed_height
78
83
 
79
- async def _async_auto_crop_data(self, tdata: TrimsData = None): # , tdata=None
84
+ async def _async_auto_crop_data(self, tdata: TrimsData): # , tdata=None
80
85
  """Load the auto crop data from the Camera config."""
81
86
  if not self.imh.auto_crop:
82
87
  trims_data = TrimCropData.from_dict(dict(tdata.to_dict())).to_list()
@@ -100,8 +105,8 @@ class AutoCrop:
100
105
 
101
106
  async def _init_auto_crop(self):
102
107
  """Initialize the auto crop data."""
103
- if not self.imh.auto_crop and self.imh.shared.vacuum_state == "docked":
104
- self.imh.auto_crop = await self._async_auto_crop_data(self.imh.shared.trims)
108
+ if not self.imh.auto_crop and self.shared.vacuum_state == "docked":
109
+ self.imh.auto_crop = await self._async_auto_crop_data(self.shared.trims)
105
110
  if self.imh.auto_crop:
106
111
  self.auto_crop_offset()
107
112
  else:
@@ -138,8 +143,8 @@ class AutoCrop:
138
143
 
139
144
  if (
140
145
  zoom
141
- and self.imh.shared.vacuum_state == "cleaning"
142
- and self.imh.shared.image_auto_zoom
146
+ and self.shared.vacuum_state == "cleaning"
147
+ and self.shared.image_auto_zoom
143
148
  ):
144
149
  # Zoom the image based on the robot's position.
145
150
  _LOGGER.debug(
@@ -209,10 +214,7 @@ class AutoCrop:
209
214
  Automatically crops and trims a numpy array and returns the processed image.
210
215
  """
211
216
  try:
212
- if self.validate_crop_dimensions(self.imh.shared):
213
- await self._init_auto_crop()
214
- else:
215
- return image_array
217
+ await self._init_auto_crop()
216
218
  if self.imh.auto_crop is None:
217
219
  _LOGGER.debug("%s: Calculating auto trim box", self.file_name)
218
220
  # Find the coordinates of the first occurrence of a non-background color
@@ -249,7 +251,7 @@ class AutoCrop:
249
251
  self.imh.trim_right,
250
252
  self.imh.trim_down,
251
253
  ).to_list()
252
- # if self.imh.shared.vacuum_state == "docked":
254
+ # if self.shared.vacuum_state == "docked":
253
255
  # await (
254
256
  # self._async_save_auto_crop_data()
255
257
  # ) # Save the crop data to the disk
@@ -0,0 +1,248 @@
1
+ """
2
+ Colors RGBA
3
+ Version: v2025.02.0
4
+ """
5
+
6
+ import logging
7
+
8
+ from .types import (
9
+ ALPHA_BACKGROUND,
10
+ ALPHA_CHARGER,
11
+ ALPHA_GO_TO,
12
+ ALPHA_MOVE,
13
+ ALPHA_NO_GO,
14
+ ALPHA_ROBOT,
15
+ ALPHA_ROOM_0,
16
+ ALPHA_ROOM_1,
17
+ ALPHA_ROOM_2,
18
+ ALPHA_ROOM_3,
19
+ ALPHA_ROOM_4,
20
+ ALPHA_ROOM_5,
21
+ ALPHA_ROOM_6,
22
+ ALPHA_ROOM_7,
23
+ ALPHA_ROOM_8,
24
+ ALPHA_ROOM_9,
25
+ ALPHA_ROOM_10,
26
+ ALPHA_ROOM_11,
27
+ ALPHA_ROOM_12,
28
+ ALPHA_ROOM_13,
29
+ ALPHA_ROOM_14,
30
+ ALPHA_ROOM_15,
31
+ ALPHA_TEXT,
32
+ ALPHA_WALL,
33
+ ALPHA_ZONE_CLEAN,
34
+ COLOR_BACKGROUND,
35
+ COLOR_CHARGER,
36
+ COLOR_GO_TO,
37
+ COLOR_MOVE,
38
+ COLOR_NO_GO,
39
+ COLOR_ROBOT,
40
+ COLOR_ROOM_0,
41
+ COLOR_ROOM_1,
42
+ COLOR_ROOM_2,
43
+ COLOR_ROOM_3,
44
+ COLOR_ROOM_4,
45
+ COLOR_ROOM_5,
46
+ COLOR_ROOM_6,
47
+ COLOR_ROOM_7,
48
+ COLOR_ROOM_8,
49
+ COLOR_ROOM_9,
50
+ COLOR_ROOM_10,
51
+ COLOR_ROOM_11,
52
+ COLOR_ROOM_12,
53
+ COLOR_ROOM_13,
54
+ COLOR_ROOM_14,
55
+ COLOR_ROOM_15,
56
+ COLOR_TEXT,
57
+ COLOR_WALL,
58
+ COLOR_ZONE_CLEAN,
59
+ )
60
+
61
+ color_transparent = (0, 0, 0, 0)
62
+ color_charger = (0, 128, 0, 255)
63
+ color_move = (238, 247, 255, 255)
64
+ color_robot = (255, 255, 204, 255)
65
+ color_no_go = (255, 0, 0, 255)
66
+ color_go_to = (0, 255, 0, 255)
67
+ color_background = (0, 125, 255, 255)
68
+ color_zone_clean = (255, 255, 255, 25)
69
+ color_wall = (255, 255, 0, 255)
70
+ color_text = (255, 255, 255, 255)
71
+ color_grey = (125, 125, 125, 255)
72
+ color_black = (0, 0, 0, 255)
73
+ color_room_0 = (135, 206, 250, 255)
74
+ color_room_1 = (176, 226, 255, 255)
75
+ color_room_2 = (164, 211, 238, 255)
76
+ color_room_3 = (141, 182, 205, 255)
77
+ color_room_4 = (96, 123, 139, 255)
78
+ color_room_5 = (224, 255, 255, 255)
79
+ color_room_6 = (209, 238, 238, 255)
80
+ color_room_7 = (180, 205, 205, 255)
81
+ color_room_8 = (122, 139, 139, 255)
82
+ color_room_9 = (175, 238, 238, 255)
83
+ color_room_10 = (84, 153, 199, 255)
84
+ color_room_11 = (133, 193, 233, 255)
85
+ color_room_12 = (245, 176, 65, 255)
86
+ color_room_13 = (82, 190, 128, 255)
87
+ color_room_14 = (72, 201, 176, 255)
88
+ color_room_15 = (165, 105, 18, 255)
89
+
90
+ rooms_color = [
91
+ color_room_0,
92
+ color_room_1,
93
+ color_room_2,
94
+ color_room_3,
95
+ color_room_4,
96
+ color_room_5,
97
+ color_room_6,
98
+ color_room_7,
99
+ color_room_8,
100
+ color_room_9,
101
+ color_room_10,
102
+ color_room_11,
103
+ color_room_12,
104
+ color_room_13,
105
+ color_room_14,
106
+ color_room_15,
107
+ ]
108
+
109
+ base_colors_array = [
110
+ color_wall,
111
+ color_zone_clean,
112
+ color_robot,
113
+ color_background,
114
+ color_move,
115
+ color_charger,
116
+ color_no_go,
117
+ color_go_to,
118
+ color_text,
119
+ ]
120
+
121
+ color_array = [
122
+ base_colors_array[0], # color_wall
123
+ base_colors_array[6], # color_no_go
124
+ base_colors_array[7], # color_go_to
125
+ color_black,
126
+ base_colors_array[2], # color_robot
127
+ base_colors_array[5], # color_charger
128
+ color_text,
129
+ base_colors_array[4], # color_move
130
+ base_colors_array[3], # color_background
131
+ base_colors_array[1], # color_zone_clean
132
+ color_transparent,
133
+ rooms_color,
134
+ ]
135
+
136
+ _LOGGER = logging.getLogger(__name__)
137
+
138
+
139
+ class ColorsManagment:
140
+ """Class to manage the colors.
141
+ Imports and updates the colors from the user configuration."""
142
+
143
+ def __init__(self, shared_var):
144
+ self.shared_var = shared_var
145
+
146
+ @staticmethod
147
+ def add_alpha_to_rgb(alpha_channels, rgb_colors):
148
+ """
149
+ Add alpha channel to RGB colors using corresponding alpha channels.
150
+
151
+ Args:
152
+ alpha_channels (List[Optional[float]]): List of alpha channel values (0.0-255.0).
153
+ rgb_colors (List[Tuple[int, int, int]]): List of RGB colors.
154
+
155
+ Returns:
156
+ List[Tuple[int, int, int, int]]: List of RGBA colors with alpha channel added.
157
+ """
158
+ if len(alpha_channels) != len(rgb_colors):
159
+ _LOGGER.error("Input lists must have the same length.")
160
+ return []
161
+
162
+ result = []
163
+ for alpha, rgb in zip(alpha_channels, rgb_colors):
164
+ try:
165
+ alpha_int = int(alpha)
166
+ if alpha_int < 0:
167
+ alpha_int = 0
168
+ elif alpha_int > 255:
169
+ alpha_int = 255
170
+
171
+ if rgb is None:
172
+ result.append((0, 0, 0, alpha_int))
173
+ else:
174
+ result.append((rgb[0], rgb[1], rgb[2], alpha_int))
175
+ except (ValueError, TypeError):
176
+ result.append(None)
177
+
178
+ return result
179
+
180
+ def set_initial_colours(self, device_info: dict) -> None:
181
+ """Set the initial colours for the map."""
182
+ try:
183
+ user_colors = [
184
+ device_info.get(COLOR_WALL, color_wall),
185
+ device_info.get(COLOR_ZONE_CLEAN, color_zone_clean),
186
+ device_info.get(COLOR_ROBOT, color_robot),
187
+ device_info.get(COLOR_BACKGROUND, color_background),
188
+ device_info.get(COLOR_MOVE, color_move),
189
+ device_info.get(COLOR_CHARGER, color_charger),
190
+ device_info.get(COLOR_NO_GO, color_no_go),
191
+ device_info.get(COLOR_GO_TO, color_go_to),
192
+ device_info.get(COLOR_TEXT, color_text),
193
+ ]
194
+ user_alpha = [
195
+ device_info.get(ALPHA_WALL, 255),
196
+ device_info.get(ALPHA_ZONE_CLEAN, 255),
197
+ device_info.get(ALPHA_ROBOT, 255),
198
+ device_info.get(ALPHA_BACKGROUND, 255),
199
+ device_info.get(ALPHA_MOVE, 255),
200
+ device_info.get(ALPHA_CHARGER, 255),
201
+ device_info.get(ALPHA_NO_GO, 255),
202
+ device_info.get(ALPHA_GO_TO, 255),
203
+ device_info.get(ALPHA_TEXT, 255),
204
+ ]
205
+ rooms_colors = [
206
+ device_info.get(COLOR_ROOM_0, color_room_0),
207
+ device_info.get(COLOR_ROOM_1, color_room_1),
208
+ device_info.get(COLOR_ROOM_2, color_room_2),
209
+ device_info.get(COLOR_ROOM_3, color_room_3),
210
+ device_info.get(COLOR_ROOM_4, color_room_4),
211
+ device_info.get(COLOR_ROOM_5, color_room_5),
212
+ device_info.get(COLOR_ROOM_6, color_room_6),
213
+ device_info.get(COLOR_ROOM_7, color_room_7),
214
+ device_info.get(COLOR_ROOM_8, color_room_8),
215
+ device_info.get(COLOR_ROOM_9, color_room_9),
216
+ device_info.get(COLOR_ROOM_10, color_room_10),
217
+ device_info.get(COLOR_ROOM_11, color_room_11),
218
+ device_info.get(COLOR_ROOM_12, color_room_12),
219
+ device_info.get(COLOR_ROOM_13, color_room_13),
220
+ device_info.get(COLOR_ROOM_14, color_room_14),
221
+ device_info.get(COLOR_ROOM_15, color_room_15),
222
+ ]
223
+ rooms_alpha = [
224
+ device_info.get(ALPHA_ROOM_0, 255),
225
+ device_info.get(ALPHA_ROOM_1, 255),
226
+ device_info.get(ALPHA_ROOM_2, 255),
227
+ device_info.get(ALPHA_ROOM_3, 255),
228
+ device_info.get(ALPHA_ROOM_4, 255),
229
+ device_info.get(ALPHA_ROOM_5, 255),
230
+ device_info.get(ALPHA_ROOM_6, 255),
231
+ device_info.get(ALPHA_ROOM_7, 255),
232
+ device_info.get(ALPHA_ROOM_8, 255),
233
+ device_info.get(ALPHA_ROOM_9, 255),
234
+ device_info.get(ALPHA_ROOM_10, 255),
235
+ device_info.get(ALPHA_ROOM_11, 255),
236
+ device_info.get(ALPHA_ROOM_12, 255),
237
+ device_info.get(ALPHA_ROOM_13, 255),
238
+ device_info.get(ALPHA_ROOM_14, 255),
239
+ device_info.get(ALPHA_ROOM_15, 255),
240
+ ]
241
+ self.shared_var.update_user_colors(
242
+ self.add_alpha_to_rgb(user_alpha, user_colors)
243
+ )
244
+ self.shared_var.update_rooms_colors(
245
+ self.add_alpha_to_rgb(rooms_alpha, rooms_colors)
246
+ )
247
+ except (ValueError, IndexError, UnboundLocalError) as e:
248
+ _LOGGER.error("Error while populating colors: %s", e)
@@ -489,7 +489,11 @@ async def async_resize_image(params: ResizeParams):
489
489
  if wsf == 0 or hsf == 0 or params.width <= 0 or params.height <= 0:
490
490
  _LOGGER.warning(
491
491
  "Invalid aspect ratio parameters: width=%s, height=%s, wsf=%s, hsf=%s. Returning original image.",
492
- params.width, params.height, wsf, hsf)
492
+ params.width,
493
+ params.height,
494
+ wsf,
495
+ hsf,
496
+ )
493
497
  return params.pil_img # Return original image if invalid
494
498
 
495
499
  new_aspect_ratio = wsf / hsf
@@ -53,7 +53,7 @@ class HypferMapImageHandler(BaseHandler):
53
53
  self.offset_left = self.shared.offset_left # offset left
54
54
  self.offset_right = self.shared.offset_right # offset right
55
55
  self.imd = ImDraw(self)
56
- self.ac = AutoCrop(self)
56
+ self.ac = AutoCrop(self, self.shared)
57
57
  self.color_grey = (128, 128, 128, 255)
58
58
  self.file_name = self.shared.file_name # file name of the vacuum.
59
59
 
@@ -64,7 +64,7 @@ class ReImageHandler(BaseHandler):
64
64
  self.offset_left = self.shared.offset_left # offset left
65
65
  self.offset_right = self.shared.offset_right # offset right
66
66
  self.imd = ImageDraw(self) # Image Draw
67
- self.crop = AutoCrop(self)
67
+ self.crop = AutoCrop(self, self.shared)
68
68
 
69
69
  async def extract_room_properties(
70
70
  self, json_data: JsonType, destinations: JsonType
@@ -260,7 +260,9 @@ class ReImageHandler(BaseHandler):
260
260
 
261
261
  async def _finalize_image(self, pil_img):
262
262
  if not self.shared.image_ref_width or not self.shared.image_ref_height:
263
- _LOGGER.warning("Image finalization failed: Invalid image dimensions. Returning original image.")
263
+ _LOGGER.warning(
264
+ "Image finalization failed: Invalid image dimensions. Returning original image."
265
+ )
264
266
  return pil_img
265
267
  if self.check_zoom_and_aspect_ratio():
266
268
  resize_params = prepare_resize_params(self, pil_img, True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b27
3
+ Version: 0.1.9b29
4
4
  Summary: A Python library to parse Valetudo map data returning a PIL Image object.
5
5
  License: Apache-2.0
6
6
  Author: Sandro Cantarella
@@ -1,20 +1,21 @@
1
1
  valetudo_map_parser/__init__.py,sha256=Wmd20bdI1btzMq-0x8NxGYWskTjdUmD-Fem9MTfziwU,810
2
2
  valetudo_map_parser/config/__init__.py,sha256=DQ9plV3ZF_K25Dp5ZQHPDoG-40dQoJNdNi-dfNeR3Zc,48
3
- valetudo_map_parser/config/auto_crop.py,sha256=J_1f4W_V1_kbALkWNd2VJosnjjSk5YR3IvHtDGmVGx0,10894
3
+ valetudo_map_parser/config/auto_crop.py,sha256=qtP_qqovnsC0442FNyizferkZinyXeSrBvRtuBznYz0,10813
4
4
  valetudo_map_parser/config/colors.py,sha256=IzTT9JvF12YGGJxaTiEJRuwUdCCsFCLzsR9seCDfYWs,6515
5
+ valetudo_map_parser/config/colors_man.py,sha256=-n2_UVvN3Swm9vxCuHe6ajDGA9XUDEPcp3UubdUY5-4,7832
5
6
  valetudo_map_parser/config/drawable.py,sha256=hsrEJCMVOrjs5sJfr26SeqJD0VNlYWwxcVkkHeaxx7U,20356
6
7
  valetudo_map_parser/config/rand25_parser.py,sha256=kIayyqVZBfQfAMkiArzqrrj9vqZB3pkgT0Y5ufrQmGA,16448
7
8
  valetudo_map_parser/config/shared.py,sha256=jk7x8xCiE0UnE1oXcZ4iIBGz1Mv0CTHQOeZN2K94eXA,9743
8
9
  valetudo_map_parser/config/types.py,sha256=wcWtYAc5sc9CWYzRJ4aOJRmuvM2rMuCfcDgAhpV8yEM,17144
9
- valetudo_map_parser/config/utils.py,sha256=5P33Ren99EUwF7vfQ-GhSeCiR6jI1ZtiKQaofbgIKp8,18914
10
+ valetudo_map_parser/config/utils.py,sha256=LExxpOesfaAeskusEfWU4nrUR068_1yM_U_1JVHYQW0,18976
10
11
  valetudo_map_parser/hypfer_draw.py,sha256=1trtil-CQcDSiAMBWPBmuP5L9MWHGTp5OlY7MX8FgDg,14932
11
- valetudo_map_parser/hypfer_handler.py,sha256=ibW2DQSWxCV2PHA6FwfIOIBDu6hryCs7ae6HD-Nhm6A,13635
12
+ valetudo_map_parser/hypfer_handler.py,sha256=g8y_hMuR1t4ILsWC5a6afGz-DTPyWbDUYP8BksX8-NQ,13648
12
13
  valetudo_map_parser/map_data.py,sha256=6FbQfgxFB6E4kcOWokReJOVSekVaE1kStyhTQhAhiOg,19469
13
14
  valetudo_map_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- valetudo_map_parser/rand25_handler.py,sha256=nFOX1yVvZrAYxfY-aij7oIz0nKcUUL28y9_gsNJWWLw,15746
15
+ valetudo_map_parser/rand25_handler.py,sha256=rYcXJX3wAwReTvvE3EzTGlbqAdEWvVRDnJgh47398W4,15789
15
16
  valetudo_map_parser/reimg_draw.py,sha256=V0JUASavKVnEtAhv7nOV4pjsRxZrNsjIUtctbKO8wvk,12507
16
- valetudo_map_parser-0.1.9b27.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
17
- valetudo_map_parser-0.1.9b27.dist-info/METADATA,sha256=SzlOLmV3VGgFRnaCjyyqrt2Cn7CIMin6rGGuwt9huyA,1029
18
- valetudo_map_parser-0.1.9b27.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
19
- valetudo_map_parser-0.1.9b27.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
20
- valetudo_map_parser-0.1.9b27.dist-info/RECORD,,
17
+ valetudo_map_parser-0.1.9b29.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
18
+ valetudo_map_parser-0.1.9b29.dist-info/METADATA,sha256=vScCR5abIYaNxqRenIkS5irR70yNEkJd72BcPuxjuTY,1029
19
+ valetudo_map_parser-0.1.9b29.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
20
+ valetudo_map_parser-0.1.9b29.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
21
+ valetudo_map_parser-0.1.9b29.dist-info/RECORD,,