From 22ea34b05462525e474816e4ee71e9385cb83dd7 Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Sat, 18 Jan 2025 08:45:51 +0000 Subject: [PATCH] fix: Fixed issue where OE sometimes returns more gas consumption data than requested, which caused issues in other parts of the system (15 minutes dev time) --- .../octopus_energy/api_client/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/octopus_energy/api_client/__init__.py b/custom_components/octopus_energy/api_client/__init__.py index 378b93b5..2b922c3b 100644 --- a/custom_components/octopus_energy/api_client/__init__.py +++ b/custom_components/octopus_energy/api_client/__init__.py @@ -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 @@ -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