reintegrate repporting features inside binding

Signed-off-by: Laurent ARNAL <laurent@clae.net>
This commit is contained in:
Laurent ARNAL 2024-01-26 17:41:08 +01:00
parent cfda793db1
commit 3f27bf3365
2 changed files with 49 additions and 55 deletions

View File

@ -57,13 +57,8 @@ public class LinkyCommandExtension extends AbstractConsoleCommandExtension imple
this.thingRegistry = thingRegistry; this.thingRegistry = thingRegistry;
} }
@Override @Override
public void execute(String[] args, Console console) { public void execute(String[] args, Console console) {
/*
if (args.length >= 2) { if (args.length >= 2) {
Thing thing = getThing(args[0]); Thing thing = getThing(args[0]);
ThingHandler thingHandler = null; ThingHandler thingHandler = null;
@ -126,11 +121,8 @@ public class LinkyCommandExtension extends AbstractConsoleCommandExtension imple
} else { } else {
printUsage(console); printUsage(console);
} }
*/
} }
@Override @Override
public List<String> getUsages() { public List<String> getUsages() {
return Arrays return Arrays

View File

@ -19,6 +19,8 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields; import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -364,52 +366,52 @@ public class LinkyHandler extends BaseThingHandler {
* @return the report as a list of string * @return the report as a list of string
*/ */
/* public synchronized List<String> reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
* public synchronized List<String> reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) { List<String> report = buildReport(startDay, endDay, separator);
* List<String> report = buildReport(startDay, endDay, separator); disconnect();
* disconnect(); return report;
* return report; }
* }
* private List<String> buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
* private List<String> buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) { List<String> report = new ArrayList<>();
* List<String> report = new ArrayList<>(); if (startDay.getYear() == endDay.getYear() && startDay.getMonthValue() == endDay.getMonthValue()) {
* if (startDay.getYear() == endDay.getYear() && startDay.getMonthValue() == endDay.getMonthValue()) { // All values in the same month
* // All values in the same month MeterReading meterReading = getConsumptionData(startDay, endDay.plusDays(1));
* Consumption result = getConsumptionData(startDay, endDay.plusDays(1)); if (meterReading != null) {
* if (result != null) {
* Aggregate days = result.aggregats.days; IntervalReading[] days = meterReading.dayValue;
* int size = (days.datas == null || days.periodes == null) ? 0
* : (days.datas.size() <= days.periodes.size() ? days.datas.size() : days.periodes.size()); int size = days.length;
* for (int i = 0; i < size; i++) {
* double consumption = days.datas.get(i); for (int i = 0; i < size; i++) {
* String line = days.periodes.get(i).dateDebut.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator; double consumption = days[i].value;
* if (consumption >= 0) { String line = days[i].date.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator;
* line += String.valueOf(consumption); if (consumption >= 0) {
* } line += String.valueOf(consumption);
* report.add(line); }
* } report.add(line);
* } else { }
* LocalDate currentDay = startDay; } else {
* while (!currentDay.isAfter(endDay)) { LocalDate currentDay = startDay;
* report.add(currentDay.format(DateTimeFormatter.ISO_LOCAL_DATE) + separator); while (!currentDay.isAfter(endDay)) {
* currentDay = currentDay.plusDays(1); 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 } else {
* LocalDate first = startDay; // Concatenate the report produced for each month between the two dates
* do { LocalDate first = startDay;
* LocalDate last = first.withDayOfMonth(first.lengthOfMonth()); do {
* if (last.isAfter(endDay)) { LocalDate last = first.withDayOfMonth(first.lengthOfMonth());
* last = endDay; if (last.isAfter(endDay)) {
* } last = endDay;
* report.addAll(buildReport(first, last, separator)); }
* first = last.plusDays(1); report.addAll(buildReport(first, last, separator));
* } while (!first.isAfter(endDay)); first = last.plusDays(1);
* } } while (!first.isAfter(endDay));
* return report; }
* } return report;
*/ }
private @Nullable MeterReading getConsumptionData(LocalDate from, LocalDate to) { private @Nullable MeterReading getConsumptionData(LocalDate from, LocalDate to) {
logger.debug("getConsumptionData from {} to {}", from.format(DateTimeFormatter.ISO_LOCAL_DATE), logger.debug("getConsumptionData from {} to {}", from.format(DateTimeFormatter.ISO_LOCAL_DATE),