From 4a76b37769bb19687abccfa911d40f6cddffc336 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sun, 15 Dec 2024 18:35:18 +0000 Subject: [PATCH] Fix issue with manual api load_scaling crash https://github.com/springfall2008/batpred/issues/1718 --- apps/predbat/fetch.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/predbat/fetch.py b/apps/predbat/fetch.py index 1577864d..171c245c 100644 --- a/apps/predbat/fetch.py +++ b/apps/predbat/fetch.py @@ -1289,6 +1289,8 @@ def basic_rates(self, info, rtype, prev=None, rate_replicate={}): # Resolve any sensor links if isinstance(rate, str) and rate[0].isalpha(): rate = self.resolve_arg("rate", rate, 0.0) + if isinstance(load_scaling, str) and load_scaling[0].isalpha(): + load_scaling = self.resolve_arg("load_scaling", load_scaling, 1.0) # Ensure the end result is a float try: @@ -1298,6 +1300,14 @@ def basic_rates(self, info, rtype, prev=None, rate_replicate={}): self.record_status("Bad rate {} provided in energy rates".format(rate), had_errors=True) continue + if load_scaling is not None: + try: + load_scaling = float(load_scaling) + except (ValueError, TypeError): + self.log("Warn: Bad load_scaling {} provided in energy rates".format(load_scaling)) + self.record_status("Warn: Bad load_scaling {} provided in energy rates".format(load_scaling), had_errors=True) + continue + # Time in minutes start_minutes = max(minutes_to_time(start, midnight), 0) end_minutes = min(minutes_to_time(end, midnight), 24 * 60 - 1)