clazz) throws LinkyException {
+ public PrmInfo getPrmInfo() throws LinkyException {
+ PrmInfo result = new PrmInfo();
+ Customer customer = getCustomer();
+ UsagePoint usagePoint = customer.usagePoints[0];
+
+ result.contractInfo = usagePoint.contracts;
+ result.usagePointInfo = usagePoint.usagePoint;
+ result.identityInfo = getIdentity();
+ result.addressInfo = getAddress();
+ result.contactInfo = getContact();
+
+ result.prmId = result.usagePointInfo.usagePointId;
+ result.customerId = customer.customerId;
+
+ return result;
+ }
+
+ public Customer getCustomer() throws LinkyException {
if (!connected) {
initialize();
}
- String data = getContent(url);
+ String data = getData(String.format("%s/%s/cache", CONTRACT_URL, config.prmId));
if (data.isEmpty()) {
- throw new LinkyException("Requesting '%s' returned an empty response", url);
+ throw new LinkyException("Requesting '%s' returned an empty response", CONTRACT_URL);
}
try {
- return Objects.requireNonNull(gson.fromJson(data, clazz));
+ CustomerReponse cResponse = gson.fromJson(data, CustomerReponse.class);
+ if (cResponse == null) {
+ throw new LinkyException("Invalid customer data received");
+ }
+ return cResponse.customer;
} catch (JsonSyntaxException e) {
- logger.debug("Invalid JSON response not matching {}: {}", clazz.getName(), data);
- throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", url);
+ logger.debug("invalid JSON response not matching PrmInfo[].class: {}", data);
+ throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", CONTRACT_URL);
}
}
- public PrmInfo getPrmInfo(String internId) throws LinkyException {
- String url = PRM_INFO_URL.formatted(internId);
- PrmInfo[] prms = getData(url, PrmInfo[].class);
- if (prms.length < 1) {
- throw new LinkyException("Invalid prms data received");
+ public AddressInfo getAddress() throws LinkyException {
+ if (!connected) {
+ initialize();
+ }
+ String data = getData(String.format("%s/%s/cache", ADDRESS_URL, "21454992660003"));
+ if (data.isEmpty()) {
+ throw new LinkyException("Requesting '%s' returned an empty response", ADDRESS_URL);
+ }
+ try {
+ CustomerReponse cResponse = gson.fromJson(data, CustomerReponse.class);
+ if (cResponse == null) {
+ throw new LinkyException("Invalid customer data received");
+ }
+ return cResponse.customer.usagePoints[0].usagePoint.usagePointAddresses;
+ } catch (JsonSyntaxException e) {
+ logger.debug("invalid JSON response not matching PrmInfo[].class: {}", data);
+ throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", ADDRESS_URL);
}
- return prms[0];
}
- public PrmDetail getPrmDetails(String internId, String prmId) throws LinkyException {
- String url = PRM_INFO_URL.formatted(internId) + "/" + prmId
- + "?embed=SITALI&embed=SITCOM&embed=SITCON&embed=SYNCON";
- return getData(url, PrmDetail.class);
+ public IdentityInfo getIdentity() throws LinkyException {
+ if (!connected) {
+ initialize();
+ }
+ String data = getData(String.format("%s/%s/cache", IDENTITY_URL, "21454992660003"));
+ if (data.isEmpty()) {
+ throw new LinkyException("Requesting '%s' returned an empty response", IDENTITY_URL);
+ }
+ try {
+ CustomerIdResponse iResponse = gson.fromJson(data, CustomerIdResponse.class);
+ if (iResponse == null) {
+ throw new LinkyException("Invalid customer data received");
+ }
+ return iResponse.identity.naturalPerson;
+ } catch (JsonSyntaxException e) {
+ logger.debug("invalid JSON response not matching PrmInfo[].class: {}", data);
+ throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", IDENTITY_URL);
+ }
}
- public UserInfo getUserInfo() throws LinkyException {
- return getData(USER_INFO_URL, UserInfo.class);
+ public ContactInfo getContact() throws LinkyException {
+ if (!connected) {
+ initialize();
+ }
+ String data = getData(String.format("%s/%s/cache", CONTACT_URL, "21454992660003"));
+ if (data.isEmpty()) {
+ throw new LinkyException("Requesting '%s' returned an empty response", CONTACT_URL);
+ }
+ try {
+ CustomerIdResponse cResponse = gson.fromJson(data, CustomerIdResponse.class);
+ if (cResponse == null) {
+ throw new LinkyException("Invalid customer data received");
+ }
+ return cResponse.contactData;
+ } catch (JsonSyntaxException e) {
+ logger.debug("invalid JSON response not matching PrmInfo[].class: {}", data);
+ throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", CONTACT_URL);
+ }
}
private Consumption getMeasures(String userId, String prmId, LocalDate from, LocalDate to, String request)
throws LinkyException {
- String url = String.format(MEASURE_URL, userId, prmId, request, from.format(API_DATE_FORMAT),
- to.format(API_DATE_FORMAT));
- ConsumptionReport report = getData(url, ConsumptionReport.class);
- return report.firstLevel.consumptions;
+ String dtStart = from.format(API_DATE_FORMAT);
+ String dtEnd = to.format(API_DATE_FORMAT);
+
+ String url = String.format(MEASURE_URL, request, prmId, dtStart, dtEnd);
+ if (!connected) {
+ initialize();
+ }
+ String data = getData(url);
+ if (data.isEmpty()) {
+ throw new LinkyException("Requesting '%s' returned an empty response", url);
+ }
+ logger.trace("getData returned {}", data);
+ try {
+ MeterResponse meterResponse = gson.fromJson(data, MeterResponse.class);
+ if (meterResponse == null) {
+ throw new LinkyException("No report data received");
+ }
+ return new ConsumptionReport().new Consumption();
+ } catch (JsonSyntaxException e) {
+ logger.debug("invalid JSON response not matching ConsumptionReport.class: {}", data);
+ throw new LinkyException(e, "Requesting '%s' returned an invalid JSON response", url);
+ }
}
public Consumption getEnergyData(String userId, String prmId, LocalDate from, LocalDate to) throws LinkyException {
- return getMeasures(userId, prmId, from, to, "energie");
+ return getMeasures(userId, prmId, from, to, "daily_consumption");
}
public Consumption getPowerData(String userId, String prmId, LocalDate from, LocalDate to) throws LinkyException {
- return getMeasures(userId, prmId, from, to, "pmax");
+ return getMeasures(userId, prmId, from, to, "daily_consumption_max_power");
}
}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/AddressInfo.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/AddressInfo.java
new file mode 100644
index 00000000000..bb7170b1649
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/AddressInfo.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class AddressInfo {
+ public String street;
+ public String locality;
+
+ @SerializedName("postalCode")
+ public String postal_code;
+
+ @SerializedName("insee_code")
+ public String inseeCode;
+
+ public String city;
+ public String country;
+
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ContactInfo.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ContactInfo.java
new file mode 100644
index 00000000000..94c40c43253
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ContactInfo.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class ContactInfo {
+ public String phone;
+ public String email;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Contracts.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Contracts.java
new file mode 100644
index 00000000000..c9bf59b0022
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Contracts.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class Contracts {
+ public String segment;
+
+ @SerializedName("subscribed_power")
+ public String subscribedPower;
+
+ @SerializedName("last_activation_date")
+ public String lastActivationDate;
+
+ @SerializedName("distribution_tariff")
+ public String distributionTariff;
+
+ @SerializedName("offpeak_hours")
+ public String offpeakHours;
+
+ @SerializedName("contract_status")
+ public String contractStatus;
+
+ @SerializedName("last_distribution_tariff_change_date")
+ public String lastDistributionTariffChangeDate;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Customer.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Customer.java
new file mode 100644
index 00000000000..de2caae124a
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/Customer.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class Customer {
+ @SerializedName("customer_id")
+ public String customerId;
+
+ @SerializedName("usage_points")
+ public UsagePoint[] usagePoints;
+
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerIdResponse.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerIdResponse.java
new file mode 100644
index 00000000000..f0e46550263
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerIdResponse.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class CustomerIdResponse {
+ @SerializedName("customer_id")
+ public String customerId;
+
+ public IdentityDetails identity;
+
+ @SerializedName("contact_data")
+ public ContactInfo contactData;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerReponse.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerReponse.java
new file mode 100644
index 00000000000..1215134483b
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/CustomerReponse.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class CustomerReponse {
+ public Customer customer;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityDetails.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityDetails.java
new file mode 100644
index 00000000000..15a07b6a275
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityDetails.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class IdentityDetails {
+ @SerializedName("natural_person")
+ public IdentityInfo naturalPerson;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityInfo.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityInfo.java
new file mode 100644
index 00000000000..8923636061c
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IdentityInfo.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class IdentityInfo {
+ public String title;
+ public String firstname;
+ public String lastname;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IntervalReading.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IntervalReading.java
new file mode 100644
index 00000000000..23bf0d4018c
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/IntervalReading.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class IntervalReading {
+ @SerializedName("value")
+ public String value;
+
+ @SerializedName("date")
+ public String date;
+
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterReading.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterReading.java
new file mode 100644
index 00000000000..8d32d1b722d
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterReading.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class MeterReading {
+ @SerializedName("usage_point_id")
+ public String usagePointId;
+
+ @SerializedName("start")
+ public String startDate;
+
+ @SerializedName("end")
+ public String endDate;
+
+ @SerializedName("quality")
+ public String quality;
+
+ @SerializedName("reading_type")
+ public ReadingType readingType;
+
+ @SerializedName("interval_reading")
+ public IntervalReading[] intervalReading;
+
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterResponse.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterResponse.java
new file mode 100644
index 00000000000..ff307fd9fee
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/MeterResponse.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class MeterResponse {
+ @SerializedName("meter_reading")
+ public MeterReading meterReading;
+
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/PrmInfo.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/PrmInfo.java
index b03f577de79..9318ac3f322 100644
--- a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/PrmInfo.java
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/PrmInfo.java
@@ -12,12 +12,22 @@
*/
package org.openhab.binding.linky.internal.dto;
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
/**
* The {@link UserInfo} holds ids of existing Prms
*
* @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
*/
public class PrmInfo {
- public String idPrm;
+ public String prmId;
+ public String customerId;
+
+ public Contracts contractInfo;
+ public UsagePointDetails usagePointInfo;
+ public ContactInfo contactInfo;
+ public AddressInfo addressInfo;
+ public IdentityInfo identityInfo;
}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ReadingType.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ReadingType.java
new file mode 100644
index 00000000000..454f04fe295
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/ReadingType.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class ReadingType {
+ @SerializedName("measurement_kind")
+ public String measurementKind;
+
+ @SerializedName("measuring_period")
+ public String measuringPeriod;
+
+ @SerializedName("unit")
+ public String unit;
+
+ @SerializedName("aggregate")
+ public String aggregate;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePoint.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePoint.java
new file mode 100644
index 00000000000..aa8d6bbf359
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePoint.java
@@ -0,0 +1,31 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class UsagePoint {
+ @SerializedName("usage_point")
+ public UsagePointDetails usagePoint;
+
+ public Contracts contracts;
+}
diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePointDetails.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePointDetails.java
new file mode 100644
index 00000000000..2b2eeb81111
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/dto/UsagePointDetails.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2010-2024 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.linky.internal.dto;
+
+import org.eclipse.jetty.jaas.spi.UserInfo;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * The {@link UserInfo} holds informations about energy delivery point
+ *
+ * @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
+ */
+
+public class UsagePointDetails {
+ @SerializedName("usage_point_id")
+ public String usagePointId;
+
+ @SerializedName("usage_point_status")
+ public String usagePointStatus;
+
+ @SerializedName("meter_type")
+ public String meterType;
+
+ @SerializedName("usage_point_addresses")
+ public AddressInfo usagePointAddresses;
+}
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 d38809b29a9..f83636f0de6 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
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
+import org.openhab.binding.linky.internal.LinkyBindingConstants;
import org.openhab.binding.linky.internal.LinkyConfiguration;
import org.openhab.binding.linky.internal.LinkyException;
import org.openhab.binding.linky.internal.api.EnedisHttpApi;
@@ -37,7 +38,8 @@ 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.PrmDetail;
import org.openhab.binding.linky.internal.dto.PrmInfo;
-import org.openhab.binding.linky.internal.dto.UserInfo;
+import org.openhab.core.auth.client.oauth2.OAuthClientService;
+import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.QuantityType;
@@ -61,6 +63,7 @@ import com.google.gson.Gson;
* sent to one of the channels.
*
* @author Gaël L'hopital - Initial contribution
+ * @author Laurent Arnal - Rewrite addon to use official dataconect API
*/
@NonNullByDefault
@@ -81,6 +84,8 @@ public class LinkyHandler extends BaseThingHandler {
private @Nullable ScheduledFuture> refreshJob;
private @Nullable EnedisHttpApi enedisApi;
+ private final OAuthFactory oAuthFactory;
+
private @NonNullByDefault({}) String prmId;
private @NonNullByDefault({}) String userId;
@@ -90,7 +95,10 @@ public class LinkyHandler extends BaseThingHandler {
ALL
}
- public LinkyHandler(Thing thing, LocaleProvider localeProvider, Gson gson, HttpClient httpClient) {
+ private @Nullable OAuthClientService oAuthService;
+
+ public LinkyHandler(Thing thing, LocaleProvider localeProvider, Gson gson, HttpClient httpClient,
+ OAuthFactory oAuthFactory) {
super(thing);
this.gson = gson;
this.httpClient = httpClient;
@@ -107,6 +115,8 @@ public class LinkyHandler extends BaseThingHandler {
return consumption;
});
+ this.oAuthFactory = oAuthFactory;
+
this.cachedPowerData = new ExpiringDayCache<>("power cache", REFRESH_FIRST_HOUR_OF_DAY, () -> {
// We request data for yesterday and the day before yesterday, even if the data for the day before yesterday
// is not needed by the binding. This is only a workaround to an API bug that will return
@@ -152,6 +162,11 @@ public class LinkyHandler extends BaseThingHandler {
LinkyConfiguration config = getConfigAs(LinkyConfiguration.class);
if (config.seemsValid()) {
+
+ OAuthClientService oAuthService = oAuthFactory.createOAuthClientService(thing.getUID().getAsString(),
+ LinkyBindingConstants.LINKY_API_TOKEN_URL, LinkyBindingConstants.LINKY_AUTHORIZE_URL, "clientId",
+ "clientSecret", LinkyBindingConstants.LINKY_SCOPES, true);
+
enedisApi = new EnedisHttpApi(config, gson, httpClient);
scheduler.submit(() -> {
try {
@@ -159,15 +174,9 @@ public class LinkyHandler extends BaseThingHandler {
api.initialize();
updateStatus(ThingStatus.ONLINE);
- if (thing.getProperties().isEmpty()) {
- UserInfo userInfo = api.getUserInfo();
- PrmInfo prmInfo = api.getPrmInfo(userInfo.userProperties.internId);
- PrmDetail details = api.getPrmDetails(userInfo.userProperties.internId, prmInfo.idPrm);
- updateProperties(Map.of(USER_ID, userInfo.userProperties.internId, PUISSANCE,
- details.situationContractuelleDtos[0].structureTarifaire().puissanceSouscrite().valeur()
- + " kVA",
- PRM_ID, prmInfo.idPrm));
- }
+ PrmInfo prmInfo = api.getPrmInfo();
+ updateProperties(Map.of(USER_ID, prmInfo.customerId, PUISSANCE,
+ prmInfo.contractInfo.subscribedPower, PRM_ID, prmInfo.prmId));
prmId = thing.getProperties().get(PRM_ID);
userId = thing.getProperties().get(USER_ID);
@@ -544,4 +553,5 @@ public class LinkyHandler extends BaseThingHandler {
aggregate.datas.get(index));
}
}
+
}
diff --git a/bundles/org.openhab.binding.linky/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.linky/src/main/resources/OH-INF/thing/thing-types.xml
index fbcdbb509e3..778b374ed24 100644
--- a/bundles/org.openhab.binding.linky/src/main/resources/OH-INF/thing/thing-types.xml
+++ b/bundles/org.openhab.binding.linky/src/main/resources/OH-INF/thing/thing-types.xml
@@ -20,19 +20,13 @@
-
-
- email
- Your Enedis Username
-
-
-
- password
- Your Enedis Password
-
-
-
- Authentication ID delivered after the captcha (see documentation).
+
+
+ Your PrmId
+
+
+
+ Your Enedis token
diff --git a/bundles/org.openhab.binding.linky/src/main/resources/templates/index.html b/bundles/org.openhab.binding.linky/src/main/resources/templates/index.html
new file mode 100644
index 00000000000..b5e0ce91ca5
--- /dev/null
+++ b/bundles/org.openhab.binding.linky/src/main/resources/templates/index.html
@@ -0,0 +1,89 @@
+
+
+
+
+
+${pageRefresh}
+Authorize openHAB binding for Smartthings
+
+
+
+
+
+
+ Authorize openHAB binding for Smartthings
+ On this page you can authorize the openHAB Smartthings biding to access your Smartthings account.
+
+ The redirect URI to use with Smartthings for this openHAB installation is
+ ${redirectUri}
+
+ ${error} ${authorizedUser}
+
+
+ Connect to SmartThings:
+
+
+
+
+
+
+
\ No newline at end of file