valetudo-map-parser 0.1.9b34__py3-none-any.whl → 0.1.9b36__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, Optional
11
+ from typing import Any, Dict, Optional, Tuple, Union
11
12
 
12
13
  import numpy as np
13
14
  from PIL import Image
@@ -75,44 +76,58 @@ class TrimCropData:
75
76
 
76
77
 
77
78
  class RoomStore:
78
- """Singleton RoomStore to store room data per vacuum."""
79
+ """
80
+ Singleton RoomStore per vacuum_id.
79
81
 
80
- _instances: Dict[str, "RoomStore"] = {} # Stores instances by vacuum ID
81
- _lock = asyncio.Lock() # Ensures thread-safe access
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
82
93
 
83
94
  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
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
90
105
  return cls._instances[vacuum_id]
91
106
 
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 {}
96
-
97
107
  def get_rooms(self) -> dict:
98
108
  """Return the stored rooms data."""
99
109
  return self.vacuums_data
100
110
 
101
111
  def set_rooms(self, rooms_data: dict) -> None:
102
- """Update the rooms data."""
112
+ """Update the stored rooms data."""
103
113
  self.vacuums_data = rooms_data
104
114
 
105
115
  def get_rooms_count(self) -> int:
106
- """Return the number of rooms stored for this vacuum."""
107
- return len(self.vacuums_data)
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
+ if len(self.vacuums_data) != 0:
122
+ return len(self.vacuums_data)
123
+ return DEFAULT_ROOMS
108
124
 
109
125
  @classmethod
110
126
  def get_all_instances(cls) -> Dict[str, "RoomStore"]:
111
- """Return all active instances (for debugging)."""
127
+ """Return all active RoomStore instances (useful for debugging)."""
112
128
  return cls._instances
113
129
 
114
130
 
115
-
116
131
  # pylint: disable=no-member
117
132
  class UserLanguageStore:
118
133
  """Store the user language data."""
@@ -625,7 +640,7 @@ class TrimsData:
625
640
  """Convert TrimData to a dictionary."""
626
641
  return asdict(self)
627
642
 
628
- def clear(self)-> dict:
643
+ def clear(self) -> dict:
629
644
  """Clear all the trims."""
630
645
  self.trim_left = 0
631
646
  self.trim_up = 0
@@ -84,7 +84,9 @@ class HypferMapImageHandler(BaseHandler, AutoCrop):
84
84
  }
85
85
  if room_properties:
86
86
  rooms = RoomStore(self.file_name, room_properties)
87
- _LOGGER.debug("%s: Rooms data extracted! %s", self.file_name, rooms.get_rooms())
87
+ _LOGGER.debug(
88
+ "%s: Rooms data extracted! %s", self.file_name, rooms.get_rooms()
89
+ )
88
90
  else:
89
91
  _LOGGER.debug("%s: Rooms data not available!", self.file_name)
90
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__)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: valetudo-map-parser
3
- Version: 0.1.9b34
3
+ Version: 0.1.9b36
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=ZUXza0nWICBUS7xbSw7jz6McrbNGRvU1GdcJjOxD0yM,17525
8
+ valetudo_map_parser/config/shared.py,sha256=tZrUDVZ5acyKPuyyp9Zca95SbZfR1Rz2hRAcIEu2LoU,10149
9
+ valetudo_map_parser/config/types.py,sha256=JiqZSDrvs3ZDji06o1BQGwrZkjDh8POlSZdVpTfvb_Y,18066
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=WIWoHUtBoML9E5dHGwMiCwf0RUrV9EvBz9qapCfs0Cs,12971
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=_etitjAnt2EBjopRgFYynJwWFwNF6M6-SlVhfCwWaN4,15256
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.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,,
17
+ valetudo_map_parser-0.1.9b36.dist-info/LICENSE,sha256=Lh-qBbuRV0-jiCIBhfV7NgdwFxQFOXH3BKOzK865hRs,10480
18
+ valetudo_map_parser-0.1.9b36.dist-info/METADATA,sha256=dsy_ac9nqUszpSKFKave0ZKedqnRIW8QAxkT691d7io,1029
19
+ valetudo_map_parser-0.1.9b36.dist-info/NOTICE.txt,sha256=5lTOuWiU9aiEnJ2go8sc7lTJ7ntMBx0g0GFnNrswCY4,2533
20
+ valetudo_map_parser-0.1.9b36.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
21
+ valetudo_map_parser-0.1.9b36.dist-info/RECORD,,