From 2bee7272828aef5133ac146af2ba8b9a78d321a3 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:43:20 +0100 Subject: [PATCH] Catch json decode error, allow decimal places in solcast update hours (#1383) * Catch json decode error, allow decimal places in solcast update hours * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- apps/predbat/predbat.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 0f8737e6..18ce216c 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -32,7 +32,7 @@ import asyncio import json -THIS_VERSION = "v8.3.5" +THIS_VERSION = "v8.3.6" PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py"] from download import predbat_update_move, predbat_update_download, check_install @@ -805,7 +805,7 @@ def download_solcast_data(self): api_keys = [api_keys] period_data = {} - max_age = self.get_arg("solcast_poll_hours", 8) * 60 + max_age = self.get_arg("solcast_poll_hours", 8.0) * 60 for api_key in api_keys: params = {"format": "json", "api_key": api_key.strip()} @@ -10366,7 +10366,12 @@ def load_current_config(self): filepath = self.config_root + "/predbat_config.json" if os.path.exists(filepath): with open(filepath, "r") as file: - settings = json.load(file) + try: + settings = json.load(file) + except json.JSONDecodeError: + self.log("Warn: Failed to load Predbat settings from {}".format(filepath)) + return + for name in settings: current = self.config_index.get(name, None) if current: