Skip to content

Commit

Permalink
add possible fix for 500 Internal Server Error
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent ARNAL <[email protected]>
  • Loading branch information
lo92fr committed Feb 5, 2025
1 parent d43ab2a commit f8c7600
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}
}

Expand Down

0 comments on commit f8c7600

Please sign in to comment.