Skip to content

Commit

Permalink
fix: Fixed issue where OE sometimes returns more gas consumption data…
Browse files Browse the repository at this point in the history
… than requested, which caused issues in other parts of the system (15 minutes dev time)
  • Loading branch information
BottlecapDave committed Jan 18, 2025
1 parent 8c2d006 commit 22ea34b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/octopus_energy/api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1217,10 +1217,11 @@ async def async_get_electricity_consumption(self, mpan: str, serial_number: str,
for item in data:
item = self.__process_consumption(item)

# For some reason, the end point returns slightly more data than we requested, so we need to filter out
# the results
# For some reason, the end point sometimes returns slightly more data than we requested, so we need to filter out the results
if (period_from is None or as_utc(item["start"]) >= period_from) and (period_to is None or as_utc(item["end"]) <= period_to):
results.append(item)
else:
_LOGGER.debug(f'Skipping gas consumption item due to outside requested scope - period_from: {period_from}; period_to: {period_to}; item: {item}; mpan: {mpan}; serial_number: {serial_number}')

results.sort(key=self.__get_interval_end)
return results
Expand Down Expand Up @@ -1279,7 +1280,12 @@ async def async_get_gas_consumption(self, mprn: str, serial_number: str, period_
results = []
for item in data:
item = self.__process_consumption(item)
results.append(item)

# For some reason, the end point sometimes returns slightly more data than we requested, so we need to filter out the results
if (period_from is None or as_utc(item["start"]) >= period_from) and (period_to is None or as_utc(item["end"]) <= period_to):
results.append(item)
else:
_LOGGER.debug(f'Skipping gas consumption item due to outside requested scope - period_from: {period_from}; period_to: {period_to}; item: {item}; mprn: {mprn}; serial_number: {serial_number}')

results.sort(key=self.__get_interval_end)
return results
Expand Down

0 comments on commit 22ea34b

Please sign in to comment.