diff --git a/EagleEyev3/__init__.py b/EagleEyev3/__init__.py index 0e5c7ee..37eb6a8 100644 --- a/EagleEyev3/__init__.py +++ b/EagleEyev3/__init__.py @@ -561,30 +561,47 @@ class Camera(Device): "Accept": "application/json" } - response = requests.get(url, headers=headers) - response_json = response.json() + try: + response = requests.get(url, headers=headers, timeout=(3, 5)) + response_json = response.json() - logging.debug(f"{response.status_code} returned from {url} with {headers} and {response.text}") - logging.info(f"{response.status_code} in get_list_of_events") + logging.debug(f"{response.status_code} returned from {url} with {headers} and {response.text}") + logging.info(f"{response.status_code} in get_list_of_events") - if response.status_code == 200: - success = True - # 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'] + if response.status_code == 200: + success = True + # 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'])] + # 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 + # 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 + except requests.exceptions.Timeout: + logging.warn(f"timeout expired for {self.id} get_llist_of_events()") + return { + "success": False, + "response_http_status": 0, + "data": None + } + + except requests.exceptions.RequestException as e: + logging.warn(e) + return { + "success": False, + "response_http_status": 0, + "data": None + } + return { "success": success, diff --git a/app.py b/app.py index fc201dd..e32e3ec 100644 --- a/app.py +++ b/app.py @@ -122,7 +122,7 @@ def camera_live_preivew(esn=None): if res: return send_file(BytesIO(res.content), mimetype='image/jpeg') else: - return send_file('static/placeholder1.png') + return send_file('static/placeholder.png') @app.route('/camera/') diff --git a/templates/cameras_partial.html b/templates/cameras_partial.html index c86cbd5..256f7a9 100644 --- a/templates/cameras_partial.html +++ b/templates/cameras_partial.html @@ -1,6 +1,6 @@ -
+

Online

    {% for camera in template_values['cameras'] %} diff --git a/templates/index.html b/templates/index.html index b94b786..15d7a3c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,18 @@ {% extends "base.html" %} {% block style %} + {% endblock %} {% block current_user %}