Skip to content

Commit

Permalink
remove the missingData stuff from previous commit, realize if was dup…
Browse files Browse the repository at this point in the history
…licate whith check already done in getConsumptionAfterChecks

Signed-off-by: Laurent ARNAL <[email protected]>
  • Loading branch information
lo92fr committed Feb 7, 2025
1 parent 4b0045e commit fead647
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class ExpiringDayCache<V> {
private @Nullable V value;
private LocalDateTime expiresAt;

public boolean missingData = false;

/**
* Create a new instance.
*
Expand Down Expand Up @@ -128,25 +126,12 @@ public boolean isExpired() {
return !LocalDateTime.now().isBefore(expiresAt);
}

public void setMissingData(boolean missingData) {
this.missingData = missingData;
}

private LocalDateTime calcNextExpiresAt() {
LocalDateTime now = LocalDateTime.now();

if (missingData) {
LocalDateTime result = now.plusMinutes(refreshInterval);
logger.debug("calcNextExpiresAt result = {}", result.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
missingData = false;
return result;
} else {
LocalDateTime limit = now.withHour(beginningHour).withMinute(beginningMinute)
.truncatedTo(ChronoUnit.MINUTES);
LocalDateTime result = now.isBefore(limit) ? limit : limit.plusDays(1);
logger.debug("calcNextExpiresAt result = {}", result.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
return result;
}
LocalDateTime limit = now.withHour(beginningHour).withMinute(beginningMinute).truncatedTo(ChronoUnit.MINUTES);
LocalDateTime result = now.isBefore(limit) ? limit : limit.plusDays(1);
logger.debug("calcNextExpiresAt result = {}", result.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
return result;
}

private LocalDateTime calcAlreadyExpired() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.openhab.binding.linky.internal.api.ExpiringDayCache;
import org.openhab.binding.linky.internal.dto.ConsumptionReport.Aggregate;
import org.openhab.binding.linky.internal.dto.ConsumptionReport.Consumption;
import org.openhab.binding.linky.internal.dto.ConsumptionReport.Data;
import org.openhab.binding.linky.internal.dto.PrmDetail;
import org.openhab.binding.linky.internal.dto.PrmInfo;
import org.openhab.binding.linky.internal.dto.UserInfo;
Expand Down Expand Up @@ -116,13 +115,6 @@ public LinkyHandler(Thing thing, LocaleProvider localeProvider, Gson gson, HttpC
Consumption consumption = getConsumptionData(today.minusDays(15), today);

if (consumption != null) {
boolean missingData = checkMissingData(consumption);
if (missingData) {
logger.debug("API have returned incomplete data, we will recheck in {} mn",
REFRESH_INTERVAL_IN_MIN);
this.cachedDailyData.setMissingData(true);
}

logData(consumption.aggregats.days, "Day", false, DateTimeFormatter.ISO_LOCAL_DATE, Target.ALL);
logData(consumption.aggregats.weeks, "Week", true, DateTimeFormatter.ISO_LOCAL_DATE_TIME, Target.ALL);
consumption = getConsumptionAfterChecks(consumption, Target.LAST);
Expand Down Expand Up @@ -531,19 +523,6 @@ public synchronized void handleCommand(ChannelUID channelUID, Command command) {
return consumption;
}

private boolean checkMissingData(@Nullable Consumption consumption) {
if (consumption != null) {

for (int idx = 0; idx < consumption.aggregats.days.datas.size(); idx++) {
Data data = consumption.aggregats.days.datas.get(idx);
if (Double.isNaN(data.valeur)) {
return true;
}
}
}
return false;
}

private void checkData(Consumption consumption) throws LinkyException {
if (consumption.aggregats.days.datas.isEmpty()) {
throw new LinkyException("Invalid consumptions data: no day period");
Expand Down

0 comments on commit fead647

Please sign in to comment.