Skip to content

Commit

Permalink
fix(api-client): fixed retrieving rates for agile and go tariffs
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Dec 31, 2021
1 parent 0245b2a commit 9a12ac5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion custom_components/octopus_energy/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,12 @@ def __process_rates(self, data, period_from, period_to, tariff_code):
starting_period_from = period_from
results = []
if ("results" in data):
items = data["results"]
items.sort(key=self.__get_valid_from)

# We need to normalise our data into 30 minute increments so that all of our rates across all tariffs are the same and it's
# easier to calculate our target rate sensors
for item in data["results"]:
for item in items:
value_exc_vat = float(item["value_exc_vat"])
value_inc_vat = float(item["value_inc_vat"])

Expand All @@ -277,6 +280,10 @@ def __process_rates(self, data, period_from, period_to, tariff_code):
# Some rates don't have end dates, so we should treat this as our period to target
if "valid_to" in item and item["valid_to"] != None:
target_date = as_utc(parse_datetime(item["valid_to"]))

# Cap our target date to our end period
if (target_date > period_to):
target_date = period_to
else:
target_date = period_to

Expand Down

0 comments on commit 9a12ac5

Please sign in to comment.