diff --git a/EagleEyev3/__init__.py b/EagleEyev3/__init__.py index fb2ba06..9350952 100644 --- a/EagleEyev3/__init__.py +++ b/EagleEyev3/__init__.py @@ -504,13 +504,16 @@ class Camera(Device): # filter events by type [self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1'] [self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1'] - + # remove duplicates seen = set() self.events['status'] = [event for event in self.events['status'] if event['endTimestamp'] and event['id'] not in seen and not seen.add(event['id'])] - seen = set() self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])] + + # sort by event startTimestamp descending + self.events['status'] = sorted(self.events['status'], key=lambda x: x['startTimestamp'], reverse=True) + self.events['motion'] = sorted(self.events['motion'], key=lambda x: x['startTimestamp'], reverse=True) else: success = False diff --git a/Playground.ipynb b/Playground.ipynb index 3ae6bdf..7e1b0b1 100644 --- a/Playground.ipynb +++ b/Playground.ipynb @@ -294,7 +294,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{\"id\":\"493237a3-2929-4886-b9c1-446325eb533e\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/493237a3-2929-4886-b9c1-446325eb533e\"}}\n" + "{\"id\":\"967034aa-aa8c-45d4-92c1-af73d0bc9f8d\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/967034aa-aa8c-45d4-92c1-af73d0bc9f8d\"}}\n" ] } ], @@ -393,7 +393,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2023-06-01T12:57:22.388-05:00 2023-06-01T06:57:22.388-05:00\n" + "2023-06-01T13:41:19.422-05:00 2023-06-01T07:41:19.422-05:00\n" ] } ], @@ -428,18 +428,6 @@ "len(een.cameras[2].events['status'])" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "f6c11a52-63e1-4b65-8149-4d0e31d13870", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "een.cameras[2].events['status']" - ] - }, { "cell_type": "code", "execution_count": null, @@ -447,7 +435,7 @@ "metadata": {}, "outputs": [], "source": [ - "len(een.cameras[2].events['motion'])" + "len(een.cameras[0].events['motion'])" ] }, { @@ -468,7 +456,11 @@ "id": "8be8d503-b46d-4ba7-884e-2c21c3987129", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#for cam in een.cameras:\n", + "# for i in cam.events['status']:\n", + "# print(f\"{cam.name} - {i['startTimestamp']} - {i['data'][0]['newStatus']['connectionStatus']} \")" + ] }, { "cell_type": "code", @@ -476,7 +468,9 @@ "id": "b761affe-ec32-4bd2-ba20-a2a6fb9db801", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#sorted(een.cameras[2].events['status'], key=lambda x: x['startTimestamp'], reverse=True) " + ] }, { "cell_type": "code",