From a888bd8dff2ee30bfe0efe5a57968876f411d22b Mon Sep 17 00:00:00 2001 From: Pavel Muhortov Date: Thu, 17 Aug 2023 19:31:47 +0300 Subject: [PATCH] fixed sequence drop due to sensor error --- cctv-scheduler.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cctv-scheduler.py b/cctv-scheduler.py index 2cd7f11..fa95fa3 100644 --- a/cctv-scheduler.py +++ b/cctv-scheduler.py @@ -683,8 +683,12 @@ class Connect: ) try: response = urllib.request.urlopen(request).read() - if not response.startswith(b'\xff\xd8'): + + try: response = str(response.decode('utf-8')) + except UnicodeDecodeError: + pass + return {"success": True, "result": response} except Exception as error: local_logger.debug(msg='error: ' + '\n' + str(error)) @@ -2430,6 +2434,7 @@ class Sensor(Connect): except Exception as error: local_logger.debug(msg='error: ' + '\n' + str(error)) return 'ERROR' + return 'ERROR' def value(self) -> str: """Public method to get sensor value. @@ -3135,7 +3140,11 @@ class Sequence: if sensor_value != 'ERROR': m = sensor_value else: - m = '' + local_logger.warning(msg="" + + "the 'ERROR' " + sensor_name + " value" + + " has been replaced with an empty string" + ) + m = "" local_logger.info(msg='' + 'action:' + key + ' = ' + action + ',' + x + ',' + y + ',' + z