From 740d814a542e2aba085088d309f2fcf7ad55fa23 Mon Sep 17 00:00:00 2001 From: wozz Date: Sat, 22 Apr 2023 13:23:45 -0400 Subject: [PATCH] catch exception --- src/amcrest2mqtt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/amcrest2mqtt.py b/src/amcrest2mqtt.py index 31054dd..7b3aae4 100644 --- a/src/amcrest2mqtt.py +++ b/src/amcrest2mqtt.py @@ -102,7 +102,12 @@ def refresh_storage_sensors(): log(f"Error fetching storage information {error}", level="WARNING") def to_gb(total): - return str(round(float(total[0]) / 1024 / 1024 / 1024, 2)) + try: + return str(round(float(total[0]) / 1024 / 1024 / 1024, 2)) + except ValueError as error: + # the api sometimes returns the string "unknown" instead of a number + log(f"Unexpected error: {error}", level="WARNING") + return 0 def signal_handler(sig, frame): # exit immediately upon receiving a second SIGINT