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

Fix issue with manual api load_scaling crash #1741

Merged
merged 1 commit into from
Dec 15, 2024
Merged
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
10 changes: 10 additions & 0 deletions apps/predbat/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Loading