Skip to content

Commit

Permalink
fix(sensor): Added more logging around failing to retrieve consumptio…
Browse files Browse the repository at this point in the history
…n rate.
  • Loading branch information
BottlecapDave committed Dec 27, 2021
1 parent fa3b33d commit dbec7a5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions custom_components/octopus_energy/sensor.py
Expand Up @@ -418,9 +418,10 @@ async def async_update(self):
consumption_from = consumption["interval_start"]
consumption_to = consumption["interval_end"]

rate = next(rate for rate in rates if rate["valid_from"] == consumption_from and rate["valid_to"] == consumption_to)
if rate == None:
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to}")
try:
rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to)
except StopIteration:
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {self._tariff_code}")

cost = (rate["value_inc_vat"] * value)
total_cost_in_pence = total_cost_in_pence + cost
Expand Down Expand Up @@ -611,9 +612,10 @@ async def async_update(self):
consumption_from = consumption["interval_start"]
consumption_to = consumption["interval_end"]

rate = next(rate for rate in rates if rate["valid_from"] == consumption_from and rate["valid_to"] == consumption_to)
if rate == None:
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to}")
try:
rate = next(r for r in rates if r["valid_from"] == consumption_from and r["valid_to"] == consumption_to)
except StopIteration:
raise Exception(f"Failed to find rate for consumption between {consumption_from} and {consumption_to} for tariff {self._tariff_code}")

cost = (rate["value_inc_vat"] * value)
total_cost_in_pence = total_cost_in_pence + cost
Expand Down

0 comments on commit dbec7a5

Please sign in to comment.