diff --git a/lib/PriceService/include/PriceService.h b/lib/PriceService/include/PriceService.h index 1a017463..822eabdb 100644 --- a/lib/PriceService/include/PriceService.h +++ b/lib/PriceService/include/PriceService.h @@ -71,6 +71,7 @@ public: PriceService(Stream*); #endif void setup(PriceServiceConfig&); + void setTimezone(Timezone* tz); bool loop(); char* getToken(); @@ -114,6 +115,7 @@ private: std::vector priceConfig; Timezone* tz = NULL; + Timezone* entsoeTz = NULL; static const uint16_t BufferSize = 256; char* buf; diff --git a/lib/PriceService/src/PriceService.cpp b/lib/PriceService/src/PriceService.cpp index 7ae7eb91..07e8a37e 100644 --- a/lib/PriceService/src/PriceService.cpp +++ b/lib/PriceService/src/PriceService.cpp @@ -32,7 +32,8 @@ PriceService::PriceService(Stream* Debug) : priceConfig(std::vector // Entso-E uses CET/CEST TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; - tz = new Timezone(CEST, CET); + entsoeTz = new Timezone(CEST, CET); + tz = entsoeTz; tomorrowFetchMinute = 15 + random(45); // Random between 13:15 and 14:00 } @@ -72,6 +73,10 @@ void PriceService::setup(PriceServiceConfig& config) { load(); } +void PriceService::setTimezone(Timezone* tz) { + this->tz = tz; +} + char* PriceService::getToken() { return this->config->entsoeToken; } @@ -153,24 +158,24 @@ float PriceService::getEnergyPriceForHour(uint8_t direction, time_t ts, int8_t h int8_t pos = hour; - breakTime(tz->toLocal(ts), tm); + breakTime(entsoeTz->toLocal(ts), tm); while(tm.Hour > 0) { ts -= 3600; - breakTime(tz->toLocal(ts), tm); + breakTime(entsoeTz->toLocal(ts), tm); pos++; } uint8_t hoursToday = 0; uint8_t todayDate = tm.Day; while(tm.Day == todayDate) { ts += 3600; - breakTime(tz->toLocal(ts), tm); + breakTime(entsoeTz->toLocal(ts), tm); hoursToday++; } uint8_t hoursTomorrow = 0; uint8_t tomorrowDate = tm.Day; while(tm.Day == tomorrowDate) { ts += 3600; - breakTime(tz->toLocal(ts), tm); + breakTime(entsoeTz->toLocal(ts), tm); hoursTomorrow++; } @@ -231,7 +236,7 @@ bool PriceService::loop() { return false; tmElements_t tm; - breakTime(tz->toLocal(t), tm); + breakTime(entsoeTz->toLocal(t), tm); if(currentDay == 0) { currentDay = tm.Day; @@ -402,7 +407,7 @@ float PriceService::getCurrencyMultiplier(const char* from, const char* to, time PricesContainer* PriceService::fetchPrices(time_t t) { if(strlen(getToken()) > 0) { tmElements_t tm; - breakTime(tz->toLocal(t), tm); + breakTime(entsoeTz->toLocal(t), tm); time_t e1 = t - (tm.Hour * 3600) - (tm.Minute * 60) - tm.Second; // Local midnight time_t e2 = e1 + SECS_PER_DAY; tmElements_t d1, d2; @@ -439,7 +444,7 @@ PricesContainer* PriceService::fetchPrices(time_t t) { } } else if(hub) { tmElements_t tm; - breakTime(tz->toLocal(t), tm); + breakTime(entsoeTz->toLocal(t), tm); String data; snprintf_P(buf, BufferSize, PSTR("http://hub.amsleser.no/hub/price/%s/%d/%d/%d?currency=%s"), diff --git a/src/AmsToMqttBridge.cpp b/src/AmsToMqttBridge.cpp index cd306b37..68127a62 100644 --- a/src/AmsToMqttBridge.cpp +++ b/src/AmsToMqttBridge.cpp @@ -977,6 +977,7 @@ void handleNtpChange() { ws.setTimezone(tz); ds.setTimezone(tz); ea.setTimezone(tz); + ps->setTimezone(tz); } config.ackNtpChange();