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;
}
@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<String> getUsages() {
return Arrays

View File

@ -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<String> reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
* List<String> report = buildReport(startDay, endDay, separator);
* disconnect();
* return report;
* }
*
* private List<String> buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
* List<String> 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<String> reportValues(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
List<String> report = buildReport(startDay, endDay, separator);
disconnect();
return report;
}
private List<String> buildReport(LocalDate startDay, LocalDate endDay, @Nullable String separator) {
List<String> 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),