Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch ValueError exception #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/amcrest2mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down