Some adjustments for fetching exchange rate

This commit is contained in:
Gunnar Skjold 2023-11-16 19:00:55 +01:00
parent 6bdd7855a7
commit 8a0c0298ab
2 changed files with 14 additions and 6 deletions

View File

@ -16,7 +16,7 @@ public:
private:
uint8_t scale = 0;
float value = 1.0;
float value = 0;
char buf[128];
uint8_t pos = 0;

View File

@ -302,7 +302,11 @@ float EntsoeApi::getCurrencyMultiplier(const char* from, const char* to, time_t
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("(EntsoeApi) url: %s\n"), buf);
if(retrieve(buf, &p)) {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("(EntsoeApi) got exchange rate %.4f\n"), p.getValue());
currencyMultiplier /= p.getValue();
if(p.getValue() > 0.0) {
currencyMultiplier /= p.getValue();
} else {
currencyMultiplier = 0;
}
} else {
currencyMultiplier = 0;
return 0;
@ -312,10 +316,14 @@ float EntsoeApi::getCurrencyMultiplier(const char* from, const char* to, time_t
currencyMultiplier = 0;
return 0;
}
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("(EntsoeApi) Resulting currency multiplier: %.4f\n"), currencyMultiplier);
tmElements_t tm;
breakTime(t, tm);
lastCurrencyFetch = now + (SECS_PER_DAY * 1000) - (((((tm.Hour * 60) + tm.Minute) * 60) + tm.Second) * 1000) + 3600000;
if(currencyMultiplier != 0) {
if(debugger->isActive(RemoteDebug::DEBUG)) debugger->printf_P(PSTR("(EntsoeApi) Resulting currency multiplier: %.4f\n"), currencyMultiplier);
tmElements_t tm;
breakTime(t, tm);
lastCurrencyFetch = now + (SECS_PER_DAY * 1000) - (((((tm.Hour * 60) + tm.Minute) * 60) + tm.Second) * 1000) + 3600000;
} else {
if(debugger->isActive(RemoteDebug::WARNING)) debugger->printf_P(PSTR("(EntsoeApi) Multiplier ended in success, but without value\n"));
}
}
return currencyMultiplier;
}