Skip to content

Commit

Permalink
fix: Fixed issue where start/end times could be incorrect on next/pre…
Browse files Browse the repository at this point in the history
…vious rate sensors
  • Loading branch information
BottlecapDave committed Feb 20, 2024
1 parent b6164e2 commit c431dac
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions custom_components/octopus_energy/utils/rate_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ def get_previous_rate_information(rates, now: datetime):
for period in reversed(rates):
if now >= period["start"] and now <= period["end"]:
current_rate = period
continue

if current_rate is not None and current_rate["value_inc_vat"] != period["value_inc_vat"]:
if len(applicable_rates) == 0 or period["value_inc_vat"] == applicable_rates[0]["value_inc_vat"]:
applicable_rates.append(period)
else:
break
elif len(applicable_rates) > 0:
break

applicable_rates.sort(key=get_from)

Expand Down Expand Up @@ -115,12 +118,15 @@ def get_next_rate_information(rates, now: datetime):
for period in rates:
if now >= period["start"] and now <= period["end"]:
current_rate = period
continue

if current_rate is not None and current_rate["value_inc_vat"] != period["value_inc_vat"]:
if len(applicable_rates) == 0 or period["value_inc_vat"] == applicable_rates[0]["value_inc_vat"]:
applicable_rates.append(period)
else:
break
elif len(applicable_rates) > 0:
break

if len(applicable_rates) > 0 and current_rate is not None:
return {
Expand Down

0 comments on commit c431dac

Please sign in to comment.