valetudo-map-parser 0.1.9b33__py3-none-any.whl → 0.1.9b34__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.
@@ -7,7 +7,7 @@ import asyncio
7
7
  import json
8
8
  import logging
9
9
  from dataclasses import asdict, dataclass
10
- from typing import Any, Dict, Tuple, Union
10
+ from typing import Any, Dict, Tuple, Union, Optional
11
11
 
12
12
  import numpy as np
13
13
  from PIL import Image
@@ -74,44 +74,43 @@ class TrimCropData:
74
74
  )
75
75
 
76
76
 
77
- # pylint: disable=no-member
78
77
  class RoomStore:
79
- """Store the room data for the vacuum."""
78
+ """Singleton RoomStore to store room data per vacuum."""
80
79
 
81
- _instance = None
82
- _lock = asyncio.Lock()
80
+ _instances: Dict[str, "RoomStore"] = {} # Stores instances by vacuum ID
81
+ _lock = asyncio.Lock() # Ensures thread-safe access
83
82
 
84
- def __init__(self):
85
- self.vacuums_data = {}
83
+ def __new__(cls, vacuum_id: str, rooms_data: Optional[dict] = None) -> "RoomStore":
84
+ """Create a new instance or return an existing one."""
85
+ if vacuum_id not in cls._instances:
86
+ instance = super().__new__(cls)
87
+ instance.vacuum_id = vacuum_id
88
+ instance.vacuums_data = rooms_data or {} # Store room data
89
+ cls._instances[vacuum_id] = instance # Store the instance
90
+ return cls._instances[vacuum_id]
86
91
 
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
+ def __init__(self, vacuum_id: str, rooms_data: Optional[dict] = None):
93
+ """Initialize the instance."""
94
+ self.vacuum_id = vacuum_id
95
+ self.vacuums_data = rooms_data or {}
92
96
 
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
97
+ def get_rooms(self) -> dict:
98
+ """Return the stored rooms data."""
99
+ return self.vacuums_data
100
+
101
+ def set_rooms(self, rooms_data: dict) -> None:
102
+ """Update the rooms data."""
103
+ self.vacuums_data = rooms_data
104
+
105
+ def get_rooms_count(self) -> int:
106
+ """Return the number of rooms stored for this vacuum."""
107
+ return len(self.vacuums_data)
108
+
109
+ @classmethod
110
+ def get_all_instances(cls) -> Dict[str, "RoomStore"]:
111
+ """Return all active instances (for debugging)."""
112
+ return cls._instances
98
113
 
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
115
114
 
116
115
 
117
116
  # pylint: disable=no-member
@@ -83,9 +83,8 @@ 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("%s: Rooms data extracted! %s", self.file_name, rooms.get_rooms())
89
88
  else:
90
89
  _LOGGER.debug("%s: Rooms data not available!", self.file_name)
91
90
  self.rooms_pos = None
@@ -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.9b34
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
@@ -6,16 +6,16 @@ valetudo_map_parser/config/colors_man.py,sha256=9b5c6XmpMzhEiunwfIjVkOk1lDyV-UFo
6
6
  valetudo_map_parser/config/drawable.py,sha256=hsrEJCMVOrjs5sJfr26SeqJD0VNlYWwxcVkkHeaxx7U,20356
7
7
  valetudo_map_parser/config/rand25_parser.py,sha256=kIayyqVZBfQfAMkiArzqrrj9vqZB3pkgT0Y5ufrQmGA,16448
8
8
  valetudo_map_parser/config/shared.py,sha256=LunTeR-qAip0VzGNMtBw665rR6-MrH3rC7U8OExY3bA,10119
9
- valetudo_map_parser/config/types.py,sha256=Zwg9W4F99M6HjeX8mlC1VSiAOTCAgKdINi3pQZkJlD8,17378
9
+ valetudo_map_parser/config/types.py,sha256=ZUXza0nWICBUS7xbSw7jz6McrbNGRvU1GdcJjOxD0yM,17525
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=WIWoHUtBoML9E5dHGwMiCwf0RUrV9EvBz9qapCfs0Cs,12971
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=_etitjAnt2EBjopRgFYynJwWFwNF6M6-SlVhfCwWaN4,15256
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.9b34.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
18
+ valetudo_map_parser-0.1.9b34.dist-info/METADATA,sha256=pgeNzSLgXBYp6K2IWxLwLrxd3BrZRYhpzDo70i4Iaes,1029
19
+ valetudo_map_parser-0.1.9b34.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
20
+ valetudo_map_parser-0.1.9b34.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
21
+ valetudo_map_parser-0.1.9b34.dist-info/RECORD,,