Skip to content

Commit

Permalink
fix date handling on deserialization
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent ARNAL <[email protected]>
  • Loading branch information
lo92fr committed Dec 21, 2024
1 parent 776e6bc commit 21a738e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/
package org.openhab.binding.linky.internal;

import static java.time.temporal.ChronoField.*;
import static org.openhab.binding.linky.internal.LinkyBindingConstants.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -56,8 +58,22 @@
public class LinkyHandlerFactory extends BaseThingHandlerFactory {
private static final DateTimeFormatter LINKY_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSX");
private static final DateTimeFormatter LINKY_LOCALDATE_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd");
private static final DateTimeFormatter LINKY_LOCALDATETIME_FORMATTER = DateTimeFormatter
.ofPattern("uuuu-MM-dd HH:mm:ss");
private static final DateTimeFormatter LINKY_LOCALDATETIME_FORMATTER = new DateTimeFormatterBuilder()
.appendPattern("uuuu-MM-dd'T'HH:mm").optionalStart().appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2)
.optionalStart().appendFraction(NANO_OF_SECOND, 0, 9, true).toFormatter();

/*
* ;
*
* DateTimeFormatter formatter1 = new DateTimeFormatterBuilder()
* .appendPattern(DATE_TIME_FORMAT_PATTERN)
* // optional decimal point followed by 1 to 6 digits
* .optionalStart()
* .appendPattern(".")
* .appendFraction(ChronoField.MICRO_OF_SECOND, 1, 6, false)
* .optionalEnd()
* .toFormatter();
*/

private final HttpClientFactory httpClientFactory;
private final OAuthFactory oAuthFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.linky.internal.dto;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import com.google.gson.annotations.SerializedName;
Expand All @@ -25,41 +27,32 @@
public class ConsumptionReport {

public class Data {
public String dateDebut;
public String dateFin;
public LocalDateTime dateDebut;
public LocalDateTime dateFin;
public String valeur;
}

public class Datas {
@SerializedName("donnees")
public List<Data> data;
public List<Data> datas;
public String unite;
}

public class ChronoData {
@SerializedName("jour")
public Datas days;

/*
* @SerializedName("SEMAINE")
* public Aggregate weeks;
*
* @SerializedName("MOIS")
* public Aggregate months;
*
* @SerializedName("ANNEE")
* public Aggregate years;
*/
@SerializedName("heure")
public Datas heure;
}

public class Consumption {
public ChronoData aggregats;

public String grandeurMetier;
public String grandeurPhysique;
public String unite;
public String mesuresPasEnum;
public List<String> labels;
public List<Double> data;
public LocalDate dateDebut;
public LocalDate dateFin;
}

@SerializedName("cons")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.time.format.DateTimeFormatter;
import java.util.List;

import org.openhab.binding.linky.internal.dto.ConsumptionReport.Data;

import com.google.gson.annotations.SerializedName;

/**
Expand Down Expand Up @@ -49,34 +51,28 @@ public class MeterReading {
public static MeterReading convertFromComsumptionReport(ConsumptionReport comsumptionReport) {
MeterReading result = new MeterReading();
result.readingType = new ReadingType();
/*
* if (comsumptionReport.firstLevel.consumptions.aggregats != null) {
* result.dayValue = fromAgregat(comsumptionReport.firstLevel.consumptions.aggregats.days);
* result.weekValue = fromAgregat(comsumptionReport.firstLevel.consumptions.aggregats.weeks);
* result.monthValue = fromAgregat(comsumptionReport.firstLevel.consumptions.aggregats.months);
* result.yearValue = fromAgregat(comsumptionReport.firstLevel.consumptions.aggregats.years);
* } else {
* result.dayValue = fromLabelsAndDatas(comsumptionReport.firstLevel.consumptions.labels,
* comsumptionReport.firstLevel.consumptions.data);
* }
*/

if (comsumptionReport.consumptions.aggregats != null) {
result.dayValue = fromAgregat(comsumptionReport.consumptions.aggregats.days);
} else {
// result.dayValue = fromLabelsAndDatas(comsumptionReport.consumptions.labels,
// comsumptionReport.consumptions.data);
}

return result;
}

public static IntervalReading[] fromAgregat(ConsumptionReport agregat) {
IntervalReading[] result = new IntervalReading[1];
/*
* int size = agregat.datas.size();
*
* for (int i = 0; i < size; i++) {
* Double data = agregat.datas.get(i);
* ConsumptionReport.Period period = agregat.periodes.get(i);
*
* result[i] = new IntervalReading();
* result[i].value = data;
* result[i].date = period.dateDebut.toLocalDateTime();
* }
*/
public static IntervalReading[] fromAgregat(ConsumptionReport.Datas agregat) {
int size = agregat.datas.size();
IntervalReading[] result = new IntervalReading[size];

for (int i = 0; i < size; i++) {
Data dataObj = agregat.datas.get(i);
result[i] = new IntervalReading();
result[i].value = Double.valueOf(dataObj.valeur);
result[i].date = dataObj.dateDebut;
}

return result;
}

Expand Down

0 comments on commit 21a738e

Please sign in to comment.