smartx-rfid 1.1.1__py3-none-any.whl → 1.1.6__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.
@@ -0,0 +1,6 @@
1
+ from pydantic import BaseModel, Field
2
+
3
+
4
+ class EventSchema(BaseModel):
5
+ event_type: str = Field("event", description="Type of the event")
6
+ event_data = Field(None, description="Associated data with the event")
@@ -27,6 +27,24 @@ class TagList:
27
27
  self._tags: Dict[str, Dict[str, Any]] = {}
28
28
  self._lock = Lock()
29
29
 
30
+ def __len__(self) -> int:
31
+ """
32
+ Return the number of stored tags.
33
+ """
34
+ return len(self._tags)
35
+
36
+ def __contains__(self, identifier: str) -> bool:
37
+ """
38
+ Check if a tag identifier exists in the list.
39
+ """
40
+ return identifier in self._tags
41
+
42
+ def __repr__(self) -> str:
43
+ """
44
+ Return a string representation of the stored tags.
45
+ """
46
+ return repr(self.get_all())
47
+
30
48
  def add(self, tag: Dict[str, Any], device: str = "Unknown") -> Tuple[bool, Optional[Dict[str, Any]]]:
31
49
  """
32
50
  Add or update a tag.
@@ -117,18 +135,26 @@ class TagList:
117
135
  with self._lock:
118
136
  return list(self._tags.values())
119
137
 
120
- def get_by_identifier(self, identifier: str) -> Optional[Dict[str, Any]]:
138
+ def get_by_identifier(self, identifier_value: str, identifier_type: str = "epc") -> Optional[Dict[str, Any]]:
121
139
  """
122
- Retrieve a tag by its unique identifier.
123
-
140
+ Retrieve a tag by its identifier.
124
141
  Args:
125
- identifier: EPC or TID value.
126
-
142
+ identifier_value: The value of the identifier (EPC or TID).
143
+ identifier_type: The type of identifier ("epc" or "tid").
127
144
  Returns:
128
145
  The tag dictionary if found, otherwise None.
129
146
  """
130
- with self._lock:
131
- return self._tags.get(identifier)
147
+ if identifier_type not in ("epc", "tid"):
148
+ identifier_type = "epc"
149
+
150
+ if self.unique_identifier == identifier_type:
151
+ return self._tags.get(identifier_value)
152
+
153
+ for tag in self._tags.values():
154
+ if tag.get(identifier_type) == identifier_value:
155
+ return tag
156
+
157
+ return None
132
158
 
133
159
  def clear(self) -> None:
134
160
  """
@@ -173,20 +199,29 @@ class TagList:
173
199
  return tag.get("tid")
174
200
  return None
175
201
 
176
- def __len__(self) -> int:
177
- """
178
- Return the number of stored tags.
202
+ def get_epcs(self) -> list[str]:
179
203
  """
180
- return len(self._tags)
204
+ Retrieve a list of all stored EPCs.
181
205
 
182
- def __contains__(self, identifier: str) -> bool:
183
- """
184
- Check if a tag identifier exists in the list.
206
+ Returns:
207
+ A list of EPC strings.
185
208
  """
186
- return identifier in self._tags
209
+ with self._lock:
210
+ return [tag["epc"] for tag in self._tags.values() if "epc" in tag]
187
211
 
188
- def __repr__(self) -> str:
212
+ def get_gtin_counts(self) -> Dict[str, int]:
189
213
  """
190
- Return a string representation of the stored tags.
214
+ Retrieve counts of tags grouped by GTIN.
215
+
216
+ Returns:
217
+ A dictionary mapping GTINs to their respective counts.
191
218
  """
192
- return repr(self.get_all())
219
+ gtin_counts: Dict[str, int] = {}
220
+ with self._lock:
221
+ for tag in self._tags.values():
222
+ gtin = tag.get("gtin")
223
+ if gtin is None:
224
+ gtin = "UNKNOWN"
225
+ gtin_counts[gtin] = gtin_counts.get(gtin, 0) + 1
226
+
227
+ return gtin_counts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smartx-rfid
3
- Version: 1.1.1
3
+ Version: 1.1.6
4
4
  Summary: SmartX RFID library
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -15,13 +15,14 @@ smartx_rfid/devices/__init__.py,sha256=EVhtb-IBLpits8dr-I1ZYYuWHw9ddqiu-98myg-iy
15
15
  smartx_rfid/devices/generic/SERIAL/_main.py,sha256=7rEgviwxfd4uWpWjVXsV0qnOAET-MxJux9PcTKiE8G8,8562
16
16
  smartx_rfid/devices/generic/TCP/_main.py,sha256=DY9c9m2ZchvUJ9n2TtPENL2GqCYS4hvdjkCAe6yGXxM,2770
17
17
  smartx_rfid/devices/generic/TCP/helpers.py,sha256=GQ_yIvmSlx_yZci6pVvZfdo1wyKcS5gtZh-VDwt3pGs,1552
18
+ smartx_rfid/schemas/events.py,sha256=0rdXXww6v1B50pGksNsGt5QhavwKpe1Jb_5f8o_SaVk,215
18
19
  smartx_rfid/schemas/tag.py,sha256=iSQkWI4MhSSVEzWhezX6UG4KJJ-FUahrfj0Hnz-H_u0,2269
19
20
  smartx_rfid/utils/__init__.py,sha256=lJA0KqFIFVDtietXGH9WwnklKkiTNvhIG6YJdDd11vk,72
20
21
  smartx_rfid/utils/event.py,sha256=7QOdiSfiMscoAaTq4U3E3asYGSVnolr9OD3FSYGh6bg,469
21
22
  smartx_rfid/utils/logger_manager.py,sha256=61HJ40wgX0hVwG4xW66IQ2jdJp8CFM_S0eoGzx8-FwU,5653
22
23
  smartx_rfid/utils/path.py,sha256=7U619vOw4BXGAKbSVdA6ZIhpCN0f-dccVax9LCclbNc,3758
23
- smartx_rfid/utils/tag_list.py,sha256=JDWJa63LA9xpEBmsjAe129WTn4UjZsSCs7OabhFYZn8,5368
24
- smartx_rfid-1.1.1.dist-info/METADATA,sha256=9waOGm6Aui10ybdDM4xM-XRVHfVi45EBQPs_eLzITE4,2636
25
- smartx_rfid-1.1.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
26
- smartx_rfid-1.1.1.dist-info/licenses/LICENSE,sha256=npGJO3HuHM3JdFNEXv1jRmP_wRYq9-ujkqJPmLxrtEw,1080
27
- smartx_rfid-1.1.1.dist-info/RECORD,,
24
+ smartx_rfid/utils/tag_list.py,sha256=b_qx0-ZkjhzKiAuCM6uuBo3QpzbmB2U1Z3CNdStCyxc,6570
25
+ smartx_rfid-1.1.6.dist-info/METADATA,sha256=pFSEmk-GgfHWxJJ_68oIrl6xd3UfjeBwbG18n419K6M,2636
26
+ smartx_rfid-1.1.6.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
27
+ smartx_rfid-1.1.6.dist-info/licenses/LICENSE,sha256=npGJO3HuHM3JdFNEXv1jRmP_wRYq9-ujkqJPmLxrtEw,1080
28
+ smartx_rfid-1.1.6.dist-info/RECORD,,