Пример #1
0
    async def get_events(
        self,
        start: Optional[datetime] = None,
        end: Optional[datetime] = None,
        limit: Optional[int] = None,
        types: Optional[List[EventType]] = None,
    ) -> List[Event]:
        """
        Same as `get_events_raw`, except

        * returns actual `Event` objects instead of raw Python dictionaries
        * filers out non-device events
        * filters out events with too low of a score

        Args:

        * `start`: start time for events
        * `end`: end time for events
        * `limit`: max number of events to return
        * `types`: list of EventTypes to get events for

        If `limit`, `start` and `end` are not provided, it will default to all events in the last 24 hours.

        If `start` is provided, then `end` or `limit` must be provided. If `end` is provided, then `start` or
        `limit` must be provided. Otherwise, you will get a 400 error from Unifi Protect
        """

        response = await self.get_events_raw(start=start,
                                             end=end,
                                             limit=limit,
                                             types=types)
        events = []

        for event_dict in response:
            # ignore unknown events
            if "type" not in event_dict or event_dict[
                    "type"] not in EventType.values():
                _LOGGER.debug("Unknown event type: %s", event_dict)
                continue

            event = create_from_unifi_dict(event_dict, api=self)

            # should never happen
            if not isinstance(event, Event):
                continue

            if event.type.value in EventType.device_events(
            ) and event.score >= self._minimum_score:
                events.append(event)

        return events
Пример #2
0
async def test_get_events(protect_client: ProtectApiClient, raw_events):
    expected_events = []
    for event in raw_events:
        if event["score"] >= 50 and event["type"] in EventType.device_events():
            expected_events.append(event)

    protect_client._minimum_score = 50

    events = await protect_client.get_events()

    assert len(events) == len(expected_events)
    for index, event in enumerate(events):
        compare_objs(event.model.value, expected_events[index], event.unifi_dict())

        if event.type.value in EventType.motion_events():
            await check_motion_event(event)
Пример #3
0
    async def get_events(
        self,
        start: Optional[datetime] = None,
        end: Optional[datetime] = None,
        limit: Optional[int] = None,
        camera_ids: Optional[List[str]] = None,
    ) -> List[Event]:
        """
        Same as `get_events_raw`, except

        * returns actual `Event` objects instead of raw Python dictionaries
        * filers out non-device events
        * filters out events with too low of a score
        """

        response = await self.get_events_raw(start=start,
                                             end=end,
                                             limit=limit,
                                             camera_ids=camera_ids)
        events = []

        for event_dict in response:
            # ignore unknown events
            if "type" not in event_dict or event_dict[
                    "type"] not in EventType.values():
                _LOGGER.debug("Unknown event type: %s", event_dict)
                continue

            event = create_from_unifi_dict(event_dict, api=self)

            # should never happen
            if not isinstance(event, Event):
                continue

            if event.type.value in EventType.device_events(
            ) and event.score >= self._minimum_score:
                events.append(event)

        return events