From 943c78d0fd26bee2e265a7034b63e126c94375bc Mon Sep 17 00:00:00 2001 From: RaHehl <7577984+RaHehl@users.noreply.github.com> Date: Thu, 23 Jan 2025 23:29:35 +0100 Subject: [PATCH] feat: update data models to allow None for optional fields --- src/uiprotect/data/devices.py | 8 ++++---- src/uiprotect/utils.py | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/uiprotect/data/devices.py b/src/uiprotect/data/devices.py index 2eab9595..74eade5e 100644 --- a/src/uiprotect/data/devices.py +++ b/src/uiprotect/data/devices.py @@ -250,8 +250,8 @@ class CameraChannel(ProtectBaseObject): height: int fps: int bitrate: int - min_bitrate: int # read only - max_bitrate: int # read only + min_bitrate: int | None = None # read only + max_bitrate: int | None = None # read only min_client_adaptive_bit_rate: int | None = None # read only min_motion_adaptive_bit_rate: int | None = None # read only fps_values: list[int] # read only @@ -543,7 +543,7 @@ def unifi_dict( class TalkbackSettings(ProtectBaseObject): type_fmt: AudioCodecs type_in: str - bind_addr: IPv4Address + bind_addr: IPv4Address | None = None bind_port: int filter_addr: str | None = None # can be used to restrict sender address filter_port: int | None = None # can be used to restrict sender port @@ -945,7 +945,7 @@ class Camera(ProtectMotionDeviceModel): feature_flags: CameraFeatureFlags lcd_message: LCDMessage | None = None lenses: list[CameraLenses] - platform: str + platform: str | None = None has_speaker: bool has_wifi: bool audio_bitrate: int diff --git a/src/uiprotect/utils.py b/src/uiprotect/utils.py index a4ff07b8..b5a4d502 100644 --- a/src/uiprotect/utils.py +++ b/src/uiprotect/utils.py @@ -241,6 +241,8 @@ def convert_unifi_data(value: Any, field: FieldInfo) -> Any: # 00000000-0000-00 0- 000-000000000000 if type_ is UUID and value == _BAD_UUID: return _EMPTY_UUID + if (type_ is IPv4Address) and value == '': + return None return type_(value) if _is_enum_type(type_): if _is_from_string_enum(type_):