From c96ab24f75097b7cb2b357138a35c5183bb1a515 Mon Sep 17 00:00:00 2001 From: Trefor Southwell <48591903+springfall2008@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:57:45 +0000 Subject: [PATCH 1/2] Supporting nordpool format rates --- apps/predbat/predbat.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index 8e62dd0a0..adb3d1a08 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -21,7 +21,7 @@ import requests import yaml -THIS_VERSION = "v7.15.11" +THIS_VERSION = "v7.15.12" TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z" TIME_FORMAT_SECONDS = "%Y-%m-%dT%H:%M:%S.%f%z" TIME_FORMAT_OCTOPUS = "%Y-%m-%d %H:%M:%S%z" @@ -9962,15 +9962,11 @@ def fetch_octopus_rates(self, entity_id, adjust_key=None): else: current_rate_id = entity_id - data_import = self.get_state(entity_id=current_rate_id, attribute="rates") + data_import = self.get_state(entity_id=current_rate_id, attribute="rates") or self.get_state(entity_id=current_rate_id, attribute="all_rates") or self.get_state(entity_id=current_rate_id, attribute="raw_today") if data_import: data_all += data_import else: - data_import = self.get_state(entity_id=current_rate_id, attribute="all_rates") - if data_import: - data_all += data_import - else: - self.log("WARN: No Octopus data in sensor {} attribute 'all_rates'".format(current_rate_id)) + self.log("WARN: No Octopus data in sensor {} attribute 'all_rates' / 'rates' / 'raw_today'".format(current_rate_id)) # Next rates if "_current_rate" in entity_id: @@ -9997,6 +9993,8 @@ def fetch_octopus_rates(self, entity_id, adjust_key=None): from_key = "start" to_key = "end" scale = 100.0 + if rate_key not in data_all[0]: + rate_key = 'value' rate_data = self.minute_data( data_all, self.forecast_days + 1, self.midnight_utc, rate_key, from_key, backwards=False, to_key=to_key, adjust_key=adjust_key, scale=scale ) From c1d866009daf01afccf2183b3b0a9b772771bc0c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Sat, 3 Feb 2024 12:59:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- apps/predbat/predbat.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/predbat/predbat.py b/apps/predbat/predbat.py index adb3d1a08..711781dc5 100644 --- a/apps/predbat/predbat.py +++ b/apps/predbat/predbat.py @@ -9962,7 +9962,11 @@ def fetch_octopus_rates(self, entity_id, adjust_key=None): else: current_rate_id = entity_id - data_import = self.get_state(entity_id=current_rate_id, attribute="rates") or self.get_state(entity_id=current_rate_id, attribute="all_rates") or self.get_state(entity_id=current_rate_id, attribute="raw_today") + data_import = ( + self.get_state(entity_id=current_rate_id, attribute="rates") + or self.get_state(entity_id=current_rate_id, attribute="all_rates") + or self.get_state(entity_id=current_rate_id, attribute="raw_today") + ) if data_import: data_all += data_import else: @@ -9994,7 +9998,7 @@ def fetch_octopus_rates(self, entity_id, adjust_key=None): to_key = "end" scale = 100.0 if rate_key not in data_all[0]: - rate_key = 'value' + rate_key = "value" rate_data = self.minute_data( data_all, self.forecast_days + 1, self.midnight_utc, rate_key, from_key, backwards=False, to_key=to_key, adjust_key=adjust_key, scale=scale )