add possible fix for 500 Internal Server Error

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Laurent ARNAL 2025-01-26 09:33:53 +01:00
parent 40202b1641
commit cd8015d8f3
2 changed files with 36 additions and 19 deletions

View File

@ -90,10 +90,16 @@ public class EnedisHttpApi {
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);

View File

@ -180,19 +180,6 @@ 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));
}
prmId = thing.getProperties().get(PRM_ID);
userId = thing.getProperties().get(USER_ID);
updateData();
disconnect();
@ -214,17 +201,41 @@ public class LinkyHandler extends BaseThingHandler {
}
}
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());
}
}