Skip to content

Commit

Permalink
Some adjustments for fetching exchange rate
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Nov 16, 2023
1 parent 0fa178a commit d4feed3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/EntsoePriceApi/include/DnbCurrParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DnbCurrParser: public Stream {

private:
uint8_t scale = 0;
float value = 1.0;
float value = 0;

char buf[128];
uint8_t pos = 0;
Expand Down
18 changes: 13 additions & 5 deletions lib/EntsoePriceApi/src/EntsoeApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit d4feed3

Please sign in to comment.