diff --git a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java index 622561452bbd9..d1bb0db2af50d 100644 --- a/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java +++ b/bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/api/EnedisHttpApi.java @@ -90,10 +90,16 @@ public EnedisHttpApi(LinkyConfiguration config, Gson gson, HttpClient httpClient this.config = config; } + public void removeAllCookie() { + httpClient.getCookieStore().removeAll(); + } + public void initialize() throws LinkyException { logger.debug("Starting login process for user: {}", config.username); try { + removeAllCookie(); + addCookie(LinkyConfiguration.INTERNAL_AUTH_ID, config.internalAuthId); logger.debug("Step 1: getting authentification"); String data = getContent(URL_ENEDIS_AUTHENTICATE); 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 50288bfc4c605..c8f2e43b3dfe1 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 @@ -180,19 +180,6 @@ public void initialize() { 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)); - } - - prmId = thing.getProperties().get(PRM_ID); - userId = thing.getProperties().get(USER_ID); - updateData(); disconnect(); @@ -214,17 +201,41 @@ public void initialize() { } } + private synchronized void updateMetaData() throws LinkyException { + EnedisHttpApi api = this.enedisApi; + if (api != null) { + 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)); + } + + prmId = thing.getProperties().get(PRM_ID); + userId = thing.getProperties().get(USER_ID); + } + } + /** * Request new data and updates channels */ private synchronized void updateData() { boolean connectedBefore = isConnected(); - updatePowerData(); - updateDailyWeeklyData(); - updateMonthlyData(); - updateYearlyData(); - if (!connectedBefore && isConnected()) { - disconnect(); + try { + updateMetaData(); + updatePowerData(); + updateDailyWeeklyData(); + updateMonthlyData(); + updateYearlyData(); + if (!connectedBefore && isConnected()) { + disconnect(); + } + } catch (LinkyException e) { + logger.error("Exception occurs during data update", e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); } }