From 4d00b2270b5b51afa798448b027b616cb70f691c Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Mon, 29 May 2023 22:19:44 +0200 Subject: [PATCH] Extend cached history to 24 hours Signed-off-by: Jacob Laursen --- .../energidataservice/internal/CacheManager.java | 2 +- .../internal/CacheManagerTest.java | 8 ++++---- .../internal/PriceListParserTest.java | 16 ++++++++-------- .../action/EnergiDataServiceActionsTest.java | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java index 089e1c55f83ca..d73ee12dd1d91 100644 --- a/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java +++ b/bundles/org.openhab.binding.energidataservice/src/main/java/org/openhab/binding/energidataservice/internal/CacheManager.java @@ -43,7 +43,7 @@ @NonNullByDefault public class CacheManager { - public static final int NUMBER_OF_HISTORIC_HOURS = 12; + public static final int NUMBER_OF_HISTORIC_HOURS = 24; public static final int SPOT_PRICE_MAX_CACHE_SIZE = 24 + 11 + NUMBER_OF_HISTORIC_HOURS; public static final int TARIFF_MAX_CACHE_SIZE = 24 * 2 + NUMBER_OF_HISTORIC_HOURS; diff --git a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/CacheManagerTest.java b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/CacheManagerTest.java index 5deecd5abd94c..a9016521198fd 100644 --- a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/CacheManagerTest.java +++ b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/CacheManagerTest.java @@ -40,7 +40,7 @@ public class CacheManagerTest { @Test void areSpotPricesFullyCachedToday() { Instant now = Instant.parse("2023-02-07T08:38:47Z"); - Instant first = Instant.parse("2023-02-06T20:00:00Z"); + Instant first = Instant.parse("2023-02-06T08:00:00Z"); Instant last = Instant.parse("2023-02-07T22:00:00Z"); Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE); CacheManager cacheManager = new CacheManager(clock); @@ -73,7 +73,7 @@ void areSpotPricesFullyCachedTodayMissingAtEnd() { @Test void areSpotPricesFullyCachedTodayOtherTimezoneIsIgnored() { Instant now = Instant.parse("2023-02-07T08:38:47Z"); - Instant first = Instant.parse("2023-02-06T20:00:00Z"); + Instant first = Instant.parse("2023-02-06T08:00:00Z"); Instant last = Instant.parse("2023-02-07T22:00:00Z"); Clock clock = Clock.fixed(now, ZoneId.of("Asia/Tokyo")); CacheManager cacheManager = new CacheManager(clock); @@ -84,7 +84,7 @@ void areSpotPricesFullyCachedTodayOtherTimezoneIsIgnored() { @Test void areSpotPricesFullyCachedTomorrow() { Instant now = Instant.parse("2023-02-07T12:00:00Z"); - Instant first = Instant.parse("2023-02-07T00:00:00Z"); + Instant first = Instant.parse("2023-02-06T12:00:00Z"); Instant last = Instant.parse("2023-02-08T22:00:00Z"); Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE); CacheManager cacheManager = new CacheManager(clock); @@ -95,7 +95,7 @@ void areSpotPricesFullyCachedTomorrow() { @Test void areHistoricSpotPricesCached() { Instant now = Instant.parse("2023-02-07T08:38:47Z"); - Instant first = Instant.parse("2023-02-06T20:00:00Z"); + Instant first = Instant.parse("2023-02-06T08:00:00Z"); Instant last = Instant.parse("2023-02-07T07:00:00Z"); Clock clock = Clock.fixed(now, EnergiDataServiceBindingConstants.NORD_POOL_TIMEZONE); CacheManager cacheManager = new CacheManager(clock); diff --git a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/PriceListParserTest.java b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/PriceListParserTest.java index 689966a500bd4..da0b31a78c950 100644 --- a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/PriceListParserTest.java +++ b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/PriceListParserTest.java @@ -71,7 +71,7 @@ void toHourlyNoChanges() throws IOException { DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(48)); + assertThat(tariffMap.size(), is(60)); assertThat(tariffMap.get(Instant.parse("2023-01-23T15:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); assertThat(tariffMap.get(Instant.parse("2023-01-23T16:00:00Z")), is(equalTo(new BigDecimal("1.05619")))); assertThat(tariffMap.get(Instant.parse("2023-01-24T15:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); @@ -85,7 +85,7 @@ void toHourlyNewTariffTomorrowWhenSummertime() throws IOException { DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(48)); + assertThat(tariffMap.size(), is(60)); assertThat(tariffMap.get(Instant.parse("2023-03-31T14:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); assertThat(tariffMap.get(Instant.parse("2023-03-31T15:00:00Z")), is(equalTo(new BigDecimal("1.05619")))); assertThat(tariffMap.get(Instant.parse("2023-04-01T14:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); @@ -99,7 +99,7 @@ void toHourlyNewTariffAtMidnight() throws IOException { DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList(), "CD"); - assertThat(tariffMap.size(), is(48)); + assertThat(tariffMap.size(), is(60)); assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("0.407717")))); assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); assertThat(tariffMap.get(Instant.parse("2023-01-01T00:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); @@ -113,7 +113,7 @@ void toHourlyDiscount() throws IOException { Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList(), "CD R"); - assertThat(tariffMap.size(), is(48)); + assertThat(tariffMap.size(), is(60)); assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("-0.407717")))); assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.0")))); assertThat(tariffMap.get(Instant.parse("2023-01-01T00:00:00Z")), is(equalTo(new BigDecimal("0.0")))); @@ -126,7 +126,7 @@ void toHourlyTariffAndDiscountIsSum() throws IOException { DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(45)); + assertThat(tariffMap.size(), is(57)); assertThat(tariffMap.get(Instant.parse("2022-11-30T15:00:00Z")), is(equalTo(new BigDecimal("0.387517")))); assertThat(tariffMap.get(Instant.parse("2022-11-30T16:00:00Z")), is(equalTo(new BigDecimal("0.973404")))); } @@ -138,7 +138,7 @@ void toHourlyTariffAndDiscountIsFree() throws IOException { DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(48)); + assertThat(tariffMap.size(), is(60)); assertThat(tariffMap.get(Instant.parse("2022-12-31T16:00:00Z")), is(equalTo(new BigDecimal("0.000000")))); assertThat(tariffMap.get(Instant.parse("2022-12-31T22:00:00Z")), is(equalTo(new BigDecimal("0.000000")))); assertThat(tariffMap.get(Instant.parse("2022-12-31T23:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); @@ -168,7 +168,7 @@ void toHourlyDailyTariffs() throws IOException { DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(56)); + assertThat(tariffMap.size(), is(68)); assertThat(tariffMap.get(Instant.parse("2023-01-28T04:00:00Z")), is(equalTo(new BigDecimal("0.2581")))); assertThat(tariffMap.get(Instant.parse("2023-01-28T05:00:00Z")), is(equalTo(new BigDecimal("0.7742")))); assertThat(tariffMap.get(Instant.parse("2023-01-28T16:00:00Z")), is(equalTo(new BigDecimal("2.3227")))); @@ -187,7 +187,7 @@ void toHourlySystemTariff() throws IOException { DatahubPricelistRecords.class); Map tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); - assertThat(tariffMap.size(), is(39)); + assertThat(tariffMap.size(), is(51)); assertThat(tariffMap.get(Instant.parse("2023-06-30T21:00:00Z")), is(equalTo(new BigDecimal("0.008")))); assertThat(tariffMap.get(Instant.parse("2023-06-30T22:00:00Z")), is(equalTo(new BigDecimal("0.697")))); } diff --git a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActionsTest.java b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActionsTest.java index fa47e09a03c9e..3170973a0b0ec 100644 --- a/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActionsTest.java +++ b/bundles/org.openhab.binding.energidataservice/src/test/java/org/openhab/binding/energidataservice/internal/action/EnergiDataServiceActionsTest.java @@ -112,7 +112,7 @@ void getPricesNetTariff() throws IOException { mockCommonDatasets(actions); Map actual = actions.getPrices("NetTariff"); - assertThat(actual.size(), is(48)); + assertThat(actual.size(), is(60)); assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("1.05619")))); } @@ -122,7 +122,7 @@ void getPricesSystemTariff() throws IOException { mockCommonDatasets(actions); Map actual = actions.getPrices("SystemTariff"); - assertThat(actual.size(), is(48)); + assertThat(actual.size(), is(60)); assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.054")))); assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.054")))); } @@ -132,7 +132,7 @@ void getPricesElectricityTax() throws IOException { mockCommonDatasets(actions); Map actual = actions.getPrices("ElectricityTax"); - assertThat(actual.size(), is(48)); + assertThat(actual.size(), is(60)); assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.008")))); assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.008")))); } @@ -142,7 +142,7 @@ void getPricesTransmissionNetTariff() throws IOException { mockCommonDatasets(actions); Map actual = actions.getPrices("TransmissionNetTariff"); - assertThat(actual.size(), is(48)); + assertThat(actual.size(), is(60)); assertThat(actual.get(Instant.parse("2023-02-04T12:00:00Z")), is(equalTo(new BigDecimal("0.058")))); assertThat(actual.get(Instant.parse("2023-02-04T16:00:00Z")), is(equalTo(new BigDecimal("0.058")))); }