uiprotect 3.1.7__py3-none-any.whl → 3.1.9__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.

Potentially problematic release.


This version of uiprotect might be problematic. Click here for more details.

uiprotect/data/base.py CHANGED
@@ -582,28 +582,24 @@ class ProtectModelWithId(ProtectModel):
582
582
  setattr(self, key, data_before_changes[key])
583
583
 
584
584
  def can_create(self, user: User) -> bool:
585
- if self.model is None:
586
- return True
587
-
588
- return user.can(self.model, PermissionNode.CREATE, self)
585
+ if (model := self.model) is not None:
586
+ return user.can(model, PermissionNode.CREATE, self)
587
+ return True
589
588
 
590
589
  def can_read(self, user: User) -> bool:
591
- if self.model is None:
592
- return True
593
-
594
- return user.can(self.model, PermissionNode.READ, self)
590
+ if (model := self.model) is not None:
591
+ return user.can(model, PermissionNode.READ, self)
592
+ return True
595
593
 
596
594
  def can_write(self, user: User) -> bool:
597
- if self.model is None:
598
- return True
599
-
600
- return user.can(self.model, PermissionNode.WRITE, self)
595
+ if (model := self.model) is not None:
596
+ return user.can(model, PermissionNode.WRITE, self)
597
+ return True
601
598
 
602
599
  def can_delete(self, user: User) -> bool:
603
- if self.model is None:
604
- return True
605
-
606
- return user.can(self.model, PermissionNode.DELETE, self)
600
+ if (model := self.model) is not None:
601
+ return user.can(model, PermissionNode.DELETE, self)
602
+ return True
607
603
 
608
604
  async def queue_update(self, callback: Callable[[], None]) -> None:
609
605
  """
@@ -615,9 +611,8 @@ class ProtectModelWithId(ProtectModel):
615
611
  self._update_sync.queue.put_nowait(callback)
616
612
 
617
613
  self._update_sync.event.set()
618
- await asyncio.sleep(
619
- 0.001,
620
- ) # release execution so other `queue_update` calls can abort
614
+ # release execution so other `queue_update` calls can abort
615
+ await asyncio.sleep(0.001)
621
616
  self._update_sync.event.clear()
622
617
 
623
618
  try:
@@ -930,8 +925,8 @@ class ProtectAdoptableDeviceModel(ProtectDeviceModel):
930
925
  }
931
926
 
932
927
  async def _api_update(self, data: dict[str, Any]) -> None:
933
- if self.model is not None:
934
- return await self._api.update_device(self.model, self.id, data)
928
+ if (model := self.model) is not None:
929
+ return await self._api.update_device(model, self.id, data)
935
930
  return None
936
931
 
937
932
  def unifi_dict(
@@ -974,10 +969,9 @@ class ProtectAdoptableDeviceModel(ProtectDeviceModel):
974
969
 
975
970
  @property
976
971
  def bridge(self) -> Bridge | None:
977
- if self.bridge_id is None:
978
- return None
979
-
980
- return self._api.bootstrap.bridges[self.bridge_id]
972
+ if (bridge_id := self.bridge_id) is not None:
973
+ return self._api.bootstrap.bridges[bridge_id]
974
+ return None
981
975
 
982
976
  @property
983
977
  def protect_url(self) -> str:
@@ -1066,7 +1060,6 @@ class ProtectMotionDeviceModel(ProtectAdoptableDeviceModel):
1066
1060
 
1067
1061
  @property
1068
1062
  def last_motion_event(self) -> Event | None:
1069
- if self.last_motion_event_id is None:
1070
- return None
1071
-
1072
- return self._api.bootstrap.events.get(self.last_motion_event_id)
1063
+ if (last_motion_event_id := self.last_motion_event_id) is not None:
1064
+ return self._api.bootstrap.events.get(last_motion_event_id)
1065
+ return None
@@ -102,31 +102,19 @@ CAMERA_EVENT_ATTR_MAP: dict[EventType, tuple[str, str]] = {
102
102
 
103
103
 
104
104
  def _process_light_event(event: Event, light: Light) -> None:
105
- if _event_is_in_range(event, light.last_motion):
106
- light.last_motion_event_id = event.id
107
-
108
-
109
- def _event_is_in_range(event: Event, dt: datetime | None) -> bool:
110
- """Check if event is in range of datetime."""
111
- return (
112
- dt is None or event.start >= dt or (event.end is not None and event.end >= dt)
113
- )
105
+ light.last_motion_event_id = event.id
114
106
 
115
107
 
116
108
  def _process_sensor_event(event: Event, sensor: Sensor) -> None:
117
109
  if event.type is EventType.MOTION_SENSOR:
118
- if _event_is_in_range(event, sensor.motion_detected_at):
119
- sensor.last_motion_event_id = event.id
110
+ sensor.last_motion_event_id = event.id
120
111
  elif event.type in {EventType.SENSOR_CLOSED, EventType.SENSOR_OPENED}:
121
- if _event_is_in_range(event, sensor.open_status_changed_at):
122
- sensor.last_contact_event_id = event.id
112
+ sensor.last_contact_event_id = event.id
123
113
  elif event.type is EventType.SENSOR_EXTREME_VALUE:
124
- if _event_is_in_range(event, sensor.extreme_value_detected_at):
125
- sensor.extreme_value_detected_at = event.end
126
- sensor.last_value_event_id = event.id
114
+ sensor.extreme_value_detected_at = event.end
115
+ sensor.last_value_event_id = event.id
127
116
  elif event.type is EventType.SENSOR_ALARM:
128
- if _event_is_in_range(event, sensor.alarm_triggered_at):
129
- sensor.last_value_event_id = event.id
117
+ sensor.last_value_event_id = event.id
130
118
 
131
119
 
132
120
  _CAMERA_SMART_AND_LINE_EVENTS = {
@@ -139,10 +127,6 @@ _CAMERA_SMART_AUDIO_EVENT = EventType.SMART_AUDIO_DETECT
139
127
  def _process_camera_event(event: Event, camera: Camera) -> None:
140
128
  event_type = event.type
141
129
  dt_attr, event_attr = CAMERA_EVENT_ATTR_MAP[event_type]
142
- dt: datetime | None = getattr(camera, dt_attr)
143
- if not _event_is_in_range(event, dt):
144
- return
145
-
146
130
  event_id = event.id
147
131
  event_start = event.start
148
132
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uiprotect
3
- Version: 3.1.7
3
+ Version: 3.1.9
4
4
  Summary: Python API for Unifi Protect (Unofficial)
5
5
  Home-page: https://github.com/uilibs/uiprotect
6
6
  License: MIT
@@ -14,8 +14,8 @@ uiprotect/cli/nvr.py,sha256=TwxEg2XT8jXAbOqv6gc7KFXELKadeItEDYweSL4_-e8,4260
14
14
  uiprotect/cli/sensors.py,sha256=fQtcDJCVxs4VbAqcavgBy2ABiVxAW3GXtna6_XFBp2k,8153
15
15
  uiprotect/cli/viewers.py,sha256=2cyrp104ffIvgT0wYGIO0G35QMkEbFe7fSVqLwDXQYQ,2171
16
16
  uiprotect/data/__init__.py,sha256=OcfuJl2qXfHcj_mdnrHhzZ5tEIZrw8auziX5IE7dn-I,2938
17
- uiprotect/data/base.py,sha256=0dfm5qLHpDJYTO04tYpEB869DkVoT0uev9BmgPR9HrA,35436
18
- uiprotect/data/bootstrap.py,sha256=aF6BJ8qgE7sEDsTKPdRXsrMsL_CTmo8Xr-TUNZjfU6I,21810
17
+ uiprotect/data/base.py,sha256=OefiljoofvG7Hp3cEp3DOabKDHW86qBXjiQnI_OUONg,35499
18
+ uiprotect/data/bootstrap.py,sha256=EWl8zWo3zSN7HWMTgcoWr3UI9WE62Mi6FJ33DTqWTII,21128
19
19
  uiprotect/data/convert.py,sha256=8h6Il_DhMkPRDPj9F_rA2UZIlTuchS3BQD24peKpk2A,2185
20
20
  uiprotect/data/devices.py,sha256=n2TVY0J-xhO7fXgrvC0hqsHjNc-B_DdySDKHOIKPeqs,110363
21
21
  uiprotect/data/nvr.py,sha256=4EzeRFogmdT96VJ9yY17rqpUMx7NuKBRnUrgRbQ5YJs,47461
@@ -30,8 +30,8 @@ uiprotect/test_util/__init__.py,sha256=whiOUb5LfDLNT3AQG6ISiKtAqO2JnhCIdFavhWDK4
30
30
  uiprotect/test_util/anonymize.py,sha256=f-8ijU-_y9r-uAbhIPn0f0I6hzJpAkvJzc8UpWihObI,8478
31
31
  uiprotect/utils.py,sha256=3SJFF8qs1Jz8t3mD8qwc1hFSocolFjdXI_v4yVlC7o4,20088
32
32
  uiprotect/websocket.py,sha256=D5DZrMzo434ecp8toNxOB5HM193kVwYw42yEcg99yMw,8029
33
- uiprotect-3.1.7.dist-info/LICENSE,sha256=INx18jhdbVXMEiiBANeKEbrbz57ckgzxk5uutmmcxGk,1111
34
- uiprotect-3.1.7.dist-info/METADATA,sha256=Fojhzsg5wyTfSca70SAEkDYH_mwt66DqasNBDpMpmME,10982
35
- uiprotect-3.1.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
- uiprotect-3.1.7.dist-info/entry_points.txt,sha256=J78AUTPrTTxgI3s7SVgrmGqDP7piX2wuuEORzhDdVRA,47
37
- uiprotect-3.1.7.dist-info/RECORD,,
33
+ uiprotect-3.1.9.dist-info/LICENSE,sha256=INx18jhdbVXMEiiBANeKEbrbz57ckgzxk5uutmmcxGk,1111
34
+ uiprotect-3.1.9.dist-info/METADATA,sha256=Dwku5PiqpAAGuSE4lMNpd98ZEXU6aY0iwpiSpV4HMM8,10982
35
+ uiprotect-3.1.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
+ uiprotect-3.1.9.dist-info/entry_points.txt,sha256=J78AUTPrTTxgI3s7SVgrmGqDP7piX2wuuEORzhDdVRA,47
37
+ uiprotect-3.1.9.dist-info/RECORD,,