diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/console/LinkyCommandExtension.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/console/LinkyCommandExtension.java index 099a49ae807..95d54a81224 100644 --- a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/console/LinkyCommandExtension.java +++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/console/LinkyCommandExtension.java @@ -57,13 +57,8 @@ public class LinkyCommandExtension extends AbstractConsoleCommandExtension imple this.thingRegistry = thingRegistry; } - - - @Override public void execute(String[] args, Console console) { - /* - if (args.length >= 2) { Thing thing = getThing(args[0]); ThingHandler thingHandler = null; @@ -126,11 +121,8 @@ public class LinkyCommandExtension extends AbstractConsoleCommandExtension imple } else { printUsage(console); } - */ - } - - + @Override public List getUsages() { return Arrays diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/handler/LinkyHandler.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/handler/LinkyHandler.java index 2af4c4f9b36..8d145fa2c0f 100644 --- a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/handler/LinkyHandler.java +++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/handler/LinkyHandler.java @@ -19,6 +19,8 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.time.temporal.WeekFields; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -364,52 +366,52 @@ public class LinkyHandler extends BaseThingHandler { * @return the report as a list of string */ - /* - * public synchronized List reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) { - * List report = buildReport(startDay, endDay, separator); - * disconnect(); - * return report; - * } - * - * private List buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) { - * List report = new ArrayList<>(); - * if (startDay.getYear() == endDay.getYear() && startDay.getMonthValue() == endDay.getMonthValue()) { - * // All values in the same month - * Consumption result = getConsumptionData(startDay, endDay.plusDays(1)); - * if (result != null) { - * Aggregate days = result.aggregats.days; - * int size = (days.datas == null || days.periodes == null) ? 0 - * : (days.datas.size() <= days.periodes.size() ? days.datas.size() : days.periodes.size()); - * for (int i = 0; i < size; i++) { - * double consumption = days.datas.get(i); - * String line = days.periodes.get(i).dateDebut.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator; - * if (consumption >= 0) { - * line += String.valueOf(consumption); - * } - * report.add(line); - * } - * } else { - * LocalDate currentDay = startDay; - * while (!currentDay.isAfter(endDay)) { - * report.add(currentDay.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator); - * currentDay = currentDay.plusDays(1); - * } - * } - * } else { - * // Concatenate the report produced for each month between the two dates - * LocalDate first = startDay; - * do { - * LocalDate last = first.withDayOfMonth(first.lengthOfMonth()); - * if (last.isAfter(endDay)) { - * last = endDay; - * } - * report.addAll(buildReport(first, last, separator)); - * first = last.plusDays(1); - * } while (!first.isAfter(endDay)); - * } - * return report; - * } - */ + public synchronized List reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) { + List report = buildReport(startDay, endDay, separator); + disconnect(); + return report; + } + + private List buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) { + List report = new ArrayList<>(); + if (startDay.getYear() == endDay.getYear() && startDay.getMonthValue() == endDay.getMonthValue()) { + // All values in the same month + MeterReading meterReading = getConsumptionData(startDay, endDay.plusDays(1)); + if (meterReading != null) { + + IntervalReading[] days = meterReading.dayValue; + + int size = days.length; + + for (int i = 0; i < size; i++) { + double consumption = days[i].value; + String line = days[i].date.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator; + if (consumption >= 0) { + line += String.valueOf(consumption); + } + report.add(line); + } + } else { + LocalDate currentDay = startDay; + while (!currentDay.isAfter(endDay)) { + report.add(currentDay.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator); + currentDay = currentDay.plusDays(1); + } + } + } else { + // Concatenate the report produced for each month between the two dates + LocalDate first = startDay; + do { + LocalDate last = first.withDayOfMonth(first.lengthOfMonth()); + if (last.isAfter(endDay)) { + last = endDay; + } + report.addAll(buildReport(first, last, separator)); + first = last.plusDays(1); + } while (!first.isAfter(endDay)); + } + return report; + } private @Nullable MeterReading getConsumptionData(LocalDate from, LocalDate to) { logger.debug("getConsumptionData from {} to {}", from.format(DateTimeFormatter.ISO_LOCAL_DATE),