uiprotect 5.3.0__tar.gz → 5.4.0__tar.gz
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.
Potentially problematic release.
This version of uiprotect might be problematic. Click here for more details.
- {uiprotect-5.3.0 → uiprotect-5.4.0}/PKG-INFO +1 -1
- {uiprotect-5.3.0 → uiprotect-5.4.0}/pyproject.toml +1 -1
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/types.py +5 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/utils.py +28 -12
- {uiprotect-5.3.0 → uiprotect-5.4.0}/LICENSE +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/README.md +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/__init__.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/__main__.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/api.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/__init__.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/backup.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/base.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/cameras.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/chimes.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/doorlocks.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/events.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/lights.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/liveviews.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/nvr.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/sensors.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/cli/viewers.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/__init__.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/base.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/bootstrap.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/convert.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/devices.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/nvr.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/user.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/data/websocket.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/exceptions.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/py.typed +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/release_cache.json +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/stream.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/test_util/__init__.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/test_util/anonymize.py +0 -0
- {uiprotect-5.3.0 → uiprotect-5.4.0}/src/uiprotect/websocket.py +0 -0
|
@@ -49,6 +49,11 @@ class ValuesEnumMixin:
|
|
|
49
49
|
_values: list[str] | None = None
|
|
50
50
|
_values_normalized: dict[str, str] | None = None
|
|
51
51
|
|
|
52
|
+
@classmethod
|
|
53
|
+
@cache
|
|
54
|
+
def from_string(cls, value: str) -> Any:
|
|
55
|
+
return cls(value) # type: ignore[call-arg]
|
|
56
|
+
|
|
52
57
|
@classmethod
|
|
53
58
|
@cache
|
|
54
59
|
def values(cls) -> list[str]:
|
|
@@ -202,6 +202,7 @@ def to_camel_case(name: str) -> str:
|
|
|
202
202
|
|
|
203
203
|
|
|
204
204
|
_EMPTY_UUID = UUID("0" * 32)
|
|
205
|
+
_SHAPE_TYPES = {SHAPE_DICT, SHAPE_LIST, SHAPE_SET}
|
|
205
206
|
|
|
206
207
|
|
|
207
208
|
def convert_unifi_data(value: Any, field: ModelField) -> Any:
|
|
@@ -211,23 +212,20 @@ def convert_unifi_data(value: Any, field: ModelField) -> Any:
|
|
|
211
212
|
if type_ is Any:
|
|
212
213
|
return value
|
|
213
214
|
|
|
214
|
-
shape
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
215
|
+
if (shape := field.shape) in _SHAPE_TYPES:
|
|
216
|
+
if shape == SHAPE_LIST and isinstance(value, list):
|
|
217
|
+
return [convert_unifi_data(v, field) for v in value]
|
|
218
|
+
if shape == SHAPE_SET and isinstance(value, list):
|
|
219
|
+
return {convert_unifi_data(v, field) for v in value}
|
|
220
|
+
if shape == SHAPE_DICT and isinstance(value, dict):
|
|
221
|
+
return {k: convert_unifi_data(v, field) for k, v in value.items()}
|
|
221
222
|
|
|
222
223
|
if value is not None:
|
|
223
224
|
if type_ in IP_TYPES:
|
|
224
|
-
|
|
225
|
-
return ip_address(value)
|
|
226
|
-
except ValueError:
|
|
227
|
-
return value
|
|
225
|
+
return _cached_ip_address(value)
|
|
228
226
|
if type_ is datetime:
|
|
229
227
|
return from_js_time(value)
|
|
230
|
-
if type_ in _CREATE_TYPES
|
|
228
|
+
if type_ in _CREATE_TYPES:
|
|
231
229
|
# cannot do this check too soon because some types cannot be used in isinstance
|
|
232
230
|
if isinstance(value, type_):
|
|
233
231
|
return value
|
|
@@ -236,16 +234,34 @@ def convert_unifi_data(value: Any, field: ModelField) -> Any:
|
|
|
236
234
|
if type_ is UUID and value == _BAD_UUID:
|
|
237
235
|
return _EMPTY_UUID
|
|
238
236
|
return type_(value)
|
|
237
|
+
if _is_enum_type(type_):
|
|
238
|
+
if _is_from_string_enum(type_):
|
|
239
|
+
return type_.from_string(value)
|
|
240
|
+
return type_(value)
|
|
239
241
|
|
|
240
242
|
return value
|
|
241
243
|
|
|
242
244
|
|
|
245
|
+
@lru_cache
|
|
246
|
+
def _cached_ip_address(value: str) -> IPv4Address | IPv6Address | str:
|
|
247
|
+
try:
|
|
248
|
+
return ip_address(value)
|
|
249
|
+
except ValueError:
|
|
250
|
+
return value
|
|
251
|
+
|
|
252
|
+
|
|
243
253
|
@lru_cache
|
|
244
254
|
def _is_enum_type(type_: Any) -> bool:
|
|
245
255
|
"""Checks if type is an Enum."""
|
|
246
256
|
return isclass(type_) and issubclass(type_, Enum)
|
|
247
257
|
|
|
248
258
|
|
|
259
|
+
@lru_cache
|
|
260
|
+
def _is_from_string_enum(type_: Any) -> bool:
|
|
261
|
+
"""Checks if Enum has from_string method."""
|
|
262
|
+
return hasattr(type_, "from_string")
|
|
263
|
+
|
|
264
|
+
|
|
249
265
|
def serialize_unifi_obj(value: Any, levels: int = -1) -> Any:
|
|
250
266
|
"""Serializes UFP data"""
|
|
251
267
|
if unifi_dict := getattr(value, "unifi_dict", None):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|