Fixed tariff peaks on wrong date and time (#1159)

* Trying to fix tariff on wrong date. Also some code cleanup

* Fix issue for ex DLMS where accumulated is always included

* Stricter time restrictions when updating history

* Adjustments after testing
This commit is contained in:
Gunnar Skjold
2026-04-09 11:41:58 +02:00
committed by GitHub
parent 6011d3169e
commit 2c96b4d94f
14 changed files with 152 additions and 133 deletions

View File

@@ -639,25 +639,22 @@ bool AmsDataStorage::isDayHappy(time_t now) {
return false;
}
if(now < FirmwareVersion::BuildEpoch) return false;
if(now < day.lastMeterReadTime) {
// If the timestamp is before the firware was built, there is something seriously wrong..
if(now < FirmwareVersion::BuildEpoch) {
return false;
}
// There are cases where the meter reports before the hour. The update method will then receive the meter timestamp as reference, thus there will not be 3600s between.
// Leaving a 100s buffer for these cases
if(now-day.lastMeterReadTime > 3500) {
// If the timestamp is before the last time we updated, there is also something wrong..
if(now < day.lastMeterReadTime) {
return false;
}
tmElements_t tm, last;
breakTime(tz->toLocal(now), tm);
breakTime(tz->toLocal(day.lastMeterReadTime), last);
if(tm.Hour != last.Hour) {
return false;
}
return true;
// If the timestamp is at the same day and hour as last update, we are happy
return tm.Day == last.Day && tm.Hour == last.Hour;
}
bool AmsDataStorage::isMonthHappy(time_t now) {