Skip to content

Commit

Permalink
feat: small cleanups to smart detect lookups (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 3, 2024
1 parent f0a3d56 commit ef21763
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/uiprotect/data/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,11 +1134,9 @@ def get_last_smart_detect_event(
smart_type: SmartDetectObjectType,
) -> Event | None:
"""Get the last smart detect event for given type."""
event_id = self.last_smart_detect_event_ids.get(smart_type)
if event_id is None:
return None

return self._api.bootstrap.events.get(event_id)
if event_id := self.last_smart_detect_event_ids.get(smart_type):
return self._api.bootstrap.events.get(event_id)
return None

@property
def last_smart_audio_detect_event(self) -> Event | None:
Expand Down Expand Up @@ -1222,19 +1220,20 @@ def active_smart_detect_types(self) -> set[SmartDetectObjectType]:
"""Get active smart detection types."""
if self.use_global:
return set(self.smart_detect_settings.object_types).intersection(
self.feature_flags.smart_detect_types,
self.feature_flags.smart_detect_types
)
return set(self.smart_detect_settings.object_types)

@property
def active_audio_detect_types(self) -> set[SmartDetectAudioType]:
"""Get active audio detection types."""
if not (enabled_audio_types := self.smart_detect_settings.audio_types):
return set()
if self.use_global:
return set(self.smart_detect_settings.audio_types or []).intersection(
self.feature_flags.smart_detect_audio_types or [],
)

return set(self.smart_detect_settings.audio_types or [])
if not (feature_audio_types := self.feature_flags.smart_detect_audio_types):
return set()
return set(feature_audio_types).intersection(enabled_audio_types)
return set(enabled_audio_types)

@property
def is_motion_detection_on(self) -> bool:
Expand Down

0 comments on commit ef21763

Please sign in to comment.