valetudo-map-parser 0.1.9b33__py3-none-any.whl → 0.1.9b35__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.
@@ -118,7 +118,9 @@ class AutoCrop:
118
118
  async def _init_auto_crop(self):
119
119
  """Initialize the auto crop data."""
120
120
  _LOGGER.debug("Auto Crop Init data: %s", str(self.auto_crop))
121
- _LOGGER.debug("Auto Crop Init trims data: %s", self.handler.shared.trims.to_dict())
121
+ _LOGGER.debug(
122
+ "Auto Crop Init trims data: %s", self.handler.shared.trims.to_dict()
123
+ )
122
124
  if not self.auto_crop: # and self.handler.shared.vacuum_state == "docked":
123
125
  self.auto_crop = await self._async_auto_crop_data(self.handler.shared.trims)
124
126
  if self.auto_crop:
@@ -237,7 +237,9 @@ class CameraSharedManager:
237
237
  _LOGGER.debug("Updating shared trims with: %s", trim_data)
238
238
  instance.trims = TrimsData.from_dict(trim_data)
239
239
 
240
- _LOGGER.debug("Shared trims successfully updated: %s", instance.trims.to_dict())
240
+ _LOGGER.debug(
241
+ "Shared trims successfully updated: %s", instance.trims.to_dict()
242
+ )
241
243
 
242
244
  except TypeError as ex:
243
245
  _LOGGER.error("Shared data can't be initialized due to a TypeError! %s", ex)
@@ -6,8 +6,9 @@ Version 0.0.1
6
6
  import asyncio
7
7
  import json
8
8
  import logging
9
+ import threading
9
10
  from dataclasses import asdict, dataclass
10
- from typing import Any, Dict, Tuple, Union
11
+ from typing import Any, Dict, Optional, Tuple, Union
11
12
 
12
13
  import numpy as np
13
14
  from PIL import Image
@@ -74,44 +75,56 @@ class TrimCropData:
74
75
  )
75
76
 
76
77
 
77
- # pylint: disable=no-member
78
78
  class RoomStore:
79
- """Store the room data for the vacuum."""
80
-
81
- _instance = None
82
- _lock = asyncio.Lock()
79
+ """
80
+ Singleton RoomStore per vacuum_id.
81
+
82
+ This class stores room data (a dictionary) for each vacuum.
83
+ Calling RoomStore(vacuum_id, rooms_data) creates a new instance for that vacuum_id if it doesn't exist,
84
+ or returns the existing one (optionally updating the data if rooms_data is provided).
85
+ """
86
+
87
+ _instances: Dict[str, "RoomStore"] = {}
88
+ _lock = threading.Lock()
89
+
90
+ # Declare instance attributes for static analysis tools like Pylint
91
+ vacuum_id: str
92
+ vacuums_data: dict
93
+
94
+ def __new__(cls, vacuum_id: str, rooms_data: Optional[dict] = None) -> "RoomStore":
95
+ with cls._lock:
96
+ if vacuum_id not in cls._instances:
97
+ instance = super(RoomStore, cls).__new__(cls)
98
+ instance.vacuum_id = vacuum_id
99
+ instance.vacuums_data = rooms_data or {}
100
+ cls._instances[vacuum_id] = instance
101
+ else:
102
+ # Update the instance's data if new rooms_data is provided.
103
+ if rooms_data is not None:
104
+ cls._instances[vacuum_id].vacuums_data = rooms_data
105
+ return cls._instances[vacuum_id]
106
+
107
+ def get_rooms(self) -> dict:
108
+ """Return the stored rooms data."""
109
+ return self.vacuums_data
110
+
111
+ def set_rooms(self, rooms_data: dict) -> None:
112
+ """Update the stored rooms data."""
113
+ self.vacuums_data = rooms_data
114
+
115
+ def get_rooms_count(self) -> int:
116
+ """
117
+ Return the number of rooms stored for this vacuum.
118
+ This is simply the number of keys in the vacuums_data dictionary.
119
+ """
120
+ if isinstance(self.vacuums_data, dict):
121
+ return len(self.vacuums_data)
122
+ return DEFAULT_ROOMS
83
123
 
84
- def __init__(self):
85
- self.vacuums_data = {}
86
-
87
- def __new__(cls):
88
- if cls._instance is None:
89
- cls._instance = super(RoomStore, cls).__new__(cls)
90
- cls._instance.vacuums_data = {}
91
- return cls._instance
92
-
93
- async def async_set_rooms_data(self, vacuum_id: str, rooms_data: dict) -> None:
94
- """Set the room data for the vacuum."""
95
- print("Setting room data")
96
- async with self._lock:
97
- self.vacuums_data[vacuum_id] = rooms_data
98
-
99
- async def async_get_rooms_data(self, vacuum_id: str) -> dict:
100
- """Get the room data for a vacuum."""
101
- async with self._lock:
102
- data = self.vacuums_data.get(vacuum_id, {})
103
- if isinstance(data, str):
104
- json_data = json.loads(data)
105
- return json_data
106
- return data
107
-
108
- async def async_get_rooms_count(self, vacuum_id: str) -> int:
109
- """Count the number of rooms for a vacuum."""
110
- async with self._lock:
111
- count = len(self.vacuums_data.get(vacuum_id, {}))
112
- if count == 0:
113
- return DEFAULT_ROOMS
114
- return count
124
+ @classmethod
125
+ def get_all_instances(cls) -> Dict[str, "RoomStore"]:
126
+ """Return all active RoomStore instances (useful for debugging)."""
127
+ return cls._instances
115
128
 
116
129
 
117
130
  # pylint: disable=no-member
@@ -626,7 +639,7 @@ class TrimsData:
626
639
  """Convert TrimData to a dictionary."""
627
640
  return asdict(self)
628
641
 
629
- def clear(self)-> dict:
642
+ def clear(self) -> dict:
630
643
  """Clear all the trims."""
631
644
  self.trim_left = 0
632
645
  self.trim_up = 0
@@ -83,9 +83,10 @@ class HypferMapImageHandler(BaseHandler, AutoCrop):
83
83
  "y": ((y_min + y_max) // 2),
84
84
  }
85
85
  if room_properties:
86
- rooms = RoomStore()
87
- await rooms.async_set_rooms_data(self.file_name, room_properties)
88
- _LOGGER.debug("%s: Rooms data extracted!", self.file_name)
86
+ rooms = RoomStore(self.file_name, room_properties)
87
+ _LOGGER.debug(
88
+ "%s: Rooms data extracted! %s", self.file_name, rooms.get_rooms()
89
+ )
89
90
  else:
90
91
  _LOGGER.debug("%s: Rooms data not available!", self.file_name)
91
92
  self.rooms_pos = None
@@ -23,11 +23,11 @@ from .config.types import (
23
23
  PilPNG,
24
24
  RobotPosition,
25
25
  RoomsProperties,
26
+ RoomStore,
26
27
  )
27
28
  from .config.utils import BaseHandler, prepare_resize_params
28
29
  from .map_data import RandImageData
29
30
  from .reimg_draw import ImageDraw
30
- from .config.types import RoomStore
31
31
 
32
32
 
33
33
  _LOGGER = logging.getLogger(__name__)
@@ -121,8 +121,8 @@ class ReImageHandler(BaseHandler, AutoCrop):
121
121
  _LOGGER.debug(
122
122
  "%s: Rooms and Zones data not available!", self.file_name
123
123
  )
124
- rooms = RoomStore()
125
- await rooms.async_set_rooms_data(self.file_name, room_properties)
124
+ rooms = RoomStore(self.file_name, room_properties)
125
+ _LOGGER.debug("Rooms Data: %s", rooms.get_rooms())
126
126
  return room_properties, zone_properties, point_properties
127
127
  except RuntimeError as e:
128
128
  _LOGGER.debug(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b33
3
+ Version: 0.1.9b35
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,21 +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=Og2rpK4izwh0aHlyZjw-tgDsQ2wXaIJGYLq1U43SSwc,12472
3
+ valetudo_map_parser/config/auto_crop.py,sha256=gYTSp4XkBTY2ir7wizBqSWdfwoZJV6Rjs5wwGw9N-pY,12494
4
4
  valetudo_map_parser/config/colors.py,sha256=IzTT9JvF12YGGJxaTiEJRuwUdCCsFCLzsR9seCDfYWs,6515
5
5
  valetudo_map_parser/config/colors_man.py,sha256=9b5c6XmpMzhEiunwfIjVkOk1lDyV-UFoasACdkGXfbo,7833
6
6
  valetudo_map_parser/config/drawable.py,sha256=hsrEJCMVOrjs5sJfr26SeqJD0VNlYWwxcVkkHeaxx7U,20356
7
7
  valetudo_map_parser/config/rand25_parser.py,sha256=kIayyqVZBfQfAMkiArzqrrj9vqZB3pkgT0Y5ufrQmGA,16448
8
- valetudo_map_parser/config/shared.py,sha256=LunTeR-qAip0VzGNMtBw665rR6-MrH3rC7U8OExY3bA,10119
9
- valetudo_map_parser/config/types.py,sha256=Zwg9W4F99M6HjeX8mlC1VSiAOTCAgKdINi3pQZkJlD8,17378
8
+ valetudo_map_parser/config/shared.py,sha256=tZrUDVZ5acyKPuyyp9Zca95SbZfR1Rz2hRAcIEu2LoU,10149
9
+ valetudo_map_parser/config/types.py,sha256=L-7Jhx-nmT6iIP3g4vMt6xmjqF-HTj2ygix_gBLRg5Y,18018
10
10
  valetudo_map_parser/config/utils.py,sha256=yPutV-FEQlDB2z3LhOOFznoprHCApF-zrQMiOtkcO-k,19198
11
11
  valetudo_map_parser/hypfer_draw.py,sha256=1trtil-CQcDSiAMBWPBmuP5L9MWHGTp5OlY7MX8FgDg,14932
12
- valetudo_map_parser/hypfer_handler.py,sha256=6bXEUfx1zSzQzWws_p35OrIgg6cQ0EfqhTbrjLWgcHU,12996
12
+ valetudo_map_parser/hypfer_handler.py,sha256=f_1oG69BA94sjcZ8O9Y6A1H-YyEutbvERzqnwgremvg,13001
13
13
  valetudo_map_parser/map_data.py,sha256=6FbQfgxFB6E4kcOWokReJOVSekVaE1kStyhTQhAhiOg,19469
14
14
  valetudo_map_parser/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- valetudo_map_parser/rand25_handler.py,sha256=UbMAkY1y9FMa11Z9vXF_zaI1EF9EQNGOpQ1jXjvgBq0,15240
15
+ valetudo_map_parser/rand25_handler.py,sha256=GxZ8UDUYEXlQme-m29HZEIstBQL3zDJr5DOsgqBolUk,15235
16
16
  valetudo_map_parser/reimg_draw.py,sha256=V0JUASavKVnEtAhv7nOV4pjsRxZrNsjIUtctbKO8wvk,12507
17
- valetudo_map_parser-0.1.9b33.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
18
- valetudo_map_parser-0.1.9b33.dist-info/METADATA,sha256=YXuqWt46jT1RDsUL6N4ZV6K7TxxiySfTg_gSREGKYrU,1029
19
- valetudo_map_parser-0.1.9b33.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
20
- valetudo_map_parser-0.1.9b33.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
21
- valetudo_map_parser-0.1.9b33.dist-info/RECORD,,
17
+ valetudo_map_parser-0.1.9b35.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
18
+ valetudo_map_parser-0.1.9b35.dist-info/METADATA,sha256=-Sa1QB1XL__hYvO9p65-pDxwgO58MihhsR7sAGebkFU,1029
19
+ valetudo_map_parser-0.1.9b35.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
20
+ valetudo_map_parser-0.1.9b35.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
21
+ valetudo_map_parser-0.1.9b35.dist-info/RECORD,,