diff --git a/custom_components/entsoe/api_client.py b/custom_components/entsoe/api_client.py index 8066303..fa41cdb 100644 --- a/custom_components/entsoe/api_client.py +++ b/custom_components/entsoe/api_client.py @@ -164,10 +164,10 @@ def process_PT15M_points(self, period: Element, start_time: datetime): # now calculate hourly averages based on available points data = {} - last_position = max(positions.keys()) - last_price = positions.get(0, 0) + last_hour = (max(positions.keys()) + 3) // 4 + last_price = 0 - for hour in range((last_position // 4) + 1): + for hour in range(last_hour): sum_prices = 0 for idx in range(hour * 4 + 1, hour * 4 + 5): last_price = positions.get(idx, last_price) diff --git a/custom_components/entsoe/test/datasets/BE_15M_exact4.xml b/custom_components/entsoe/test/datasets/BE_15M_exact4.xml new file mode 100644 index 0000000..3340dd3 --- /dev/null +++ b/custom_components/entsoe/test/datasets/BE_15M_exact4.xml @@ -0,0 +1,49 @@ + + + 64e2af3a87c2404cbea80edc067a1b6f + 1 + A44 + 10X1001A1001A450 + A32 + 10X1001A1001A450 + A33 + 2024-10-07T14:36:40Z + + 2024-10-05T22:00Z + 2024-10-06T22:00Z + + + 1 + A01 + A62 + 10YBE----------2 + 10YBE----------2 + A01 + EUR + MWH + A03 + + + 2024-10-05T22:00Z + 2024-10-05T23:00Z + + PT15M + + 1 + 55.35 + + + 2 + 44.22 + + + 3 + 40.32 + + + 4 + 31.86 + + + + diff --git a/custom_components/entsoe/test/test_api_client.py b/custom_components/entsoe/test/test_api_client.py index e71dfb8..cc3eeb0 100644 --- a/custom_components/entsoe/test/test_api_client.py +++ b/custom_components/entsoe/test/test_api_client.py @@ -223,6 +223,19 @@ def test_be_15M_avg(self): }, ) + def test_be_exact4(self): + with open("./datasets/BE_15M_exact4.xml") as f: + data = f.read() + + self.maxDiff = None + self.assertDictEqual( + self.client.parse_price_document(data), + { + # part 1 - 15M resolution + datetime.fromisoformat("2024-10-05T22:00:00Z"): 42.94, # average + }, + ) + if __name__ == "__main__": unittest.main()