Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linky] Fixes for change in Enedis API on 2024 December 20 #17945

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lo92fr
Copy link
Contributor

@lo92fr lo92fr commented Dec 21, 2024

Fixes for Linky Enedis December web site change

This pull request is about fixing the linky addon after the change that was made on Enedis side to the Web Site.
This is linked to issue:
#17936

Description

Mainly, changes are :
- URL for data is now mes-mesures-prm and not mes-mesures.
- Dto format have changed : mainly merge data & date, field renaming, and moving.
- Some changes on date format.

@wborn wborn linked an issue Dec 21, 2024 that may be closed by this pull request
@lolodomo
Copy link
Contributor

Thank you @lo92fr , I will review and test.

@lolodomo
Copy link
Contributor

I still have Java 17 and Java 21 on my dev PC so it should be easy to build a JAR for Java 17.
But in case I would have only Java 21, do you know what is the maven command to execute to build a JAR compatible with Java 17 / OH 4.3 ?
@holgerfriedrich I am sure you know ;)

@jlaur jlaur changed the title Linky : Fixes for change in Enedis API on 2024 December 20 ! [linky] Fixes for change in Enedis API on 2024 December 20 Dec 21, 2024
@holgerfriedrich
Copy link
Member

@lolodomo Hopefully it is just:

mvn install -Pj17 -Dohc.version=4.3.0

https://community.openhab.org/t/openhab-5-x-snapshot-requires-java-21/160890/5

@lolodomo
Copy link
Contributor

@lo92fr : does not work for me => Error requesting 'https://alex.microapplications.enedis.fr/mes-mesures-prm/api/private/v1/personnes/xxxxx/prms/yyyyy/donnees-energetiques?mesuresTypeCode=ENERGIE&mesuresCorrigees=false&typeDonnees=CONS&dateDebut=2023-01-01': {"message":"Internal server error. Please try again","code":"INTERNAL_SERVER_ERROR"}

Will see if it work in next tries (next hours).

@lolodomo lolodomo added the bug An unexpected problem or unintended behavior of an add-on label Dec 21, 2024
@lo92fr
Copy link
Contributor Author

lo92fr commented Dec 21, 2024

if it work in next tries (next

It still work on my side, strange.
Does the xxx in URL correctly formatted with something like MPSxxxYYY ?

Laurent.

@lolodomo
Copy link
Contributor

lolodomo commented Dec 21, 2024

Does the xxx in URL correctly formatted with something like MPSxxxYYY ?

3 letters then 3 numbers and then 3 letters.
Starts by N in my case.
If I correctly remember, it is the reference of my counter?

@lo92fr
Copy link
Contributor Author

lo92fr commented Dec 21, 2024

If it's still does not work, can you please:

  • check that you have the new version of the website. Look like this:
    image

  • When you load the page, take a look on the browser debugger, new URL appears at the bottom of the list.
    Is it the same and does it works correctly in your browser session ?

image

Thks,
Laurent.

@lolodomo
Copy link
Contributor

lolodomo commented Dec 21, 2024

Yes, I have the same page on their website.
The requests are similar, the binding request just has an additional parameter "dateDebut".
When I run in my browser session while I am logged to the website, the binding URL works well!

@lolodomo
Copy link
Contributor

Now the binding is working! Even after I disconnect from the website in my browser.
Maybe you need to connect at least one time to the new website version ?

Comment on lines 220 to 221
updateState(PEAK_TIMESTAMP, new DateTimeType(
days.datas.get(days.datas.size() - 1).dateDebut.atZone(this.timeZoneProvider.getTimeZone())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed very recently, just before releasing 4.3. We don't need to pass a ZonedDateTipe; DateTimeType just needs an Instant as parameter. So you do not need TimeZoneProvider .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lolodomo,

I'm not sure to understant. Do you say to use the DateTimeType constructor that take an instant, something like this.
updateState(PEAK_TIMESTAMP,
new DateTimeType(days.datas.get(days.datas.size() - 1).dateDebut.toInstant(zoneOffset)));

The matter is that I still need to find a zoneOffset in this case.
The Enedis API return a LocalDateTime at offset of the current zone.
The DateTimeType if I undestand correctly want a universal time.

So somewhere we need to convert from local to universal using a timezone ?

Laurent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlaur is our specialist with date. Please advice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If days.datas.get(days.datas.size() - 1).dateDebut is a LocalDateTime, the implementation is already correct. If it is an Instant there is no need to convert to ZonedDateTime.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation is already correct

@jlaur : you mean @lo92fr proposed code is correct ?
I am a little lost, why should we consider the timezone setup in server ?
Imagine that for a strange reason I setup timezone in OH server to UTC+5. I am convinced Enedis provides dates in France timezone, that is UTC+1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jlaur,

No there is no way to configure the home location / time-zone in the eneids account.
I think this is a hidden fixed value that is link to your PDL (Point of Delivery) that is linked to your postal address.

So I think the best is to assume that the api just return a local Datetime, and that the openhab server is on the same timezone.

The only scenario I can see that can be bad is someone having two different house : let say one in France, and one in another timezone like Guadeloupe, and that at the same time will use only one openhab instance for the two house.
In this case, result can be wrong.

Laurent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't the timezone be a configuration setting of the PDL thing ? Defaulted to France/Paris ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @clinique,

Yes, this a solution.
Like this we will be able to handle specific case.

Laurent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the default should then be openHAB time-zone rather than France/Paris, given what @lo92fr wrote about the service probably using time-zone of PDL. But since it's not documented or proven, I guess it doesn't matter much, as long as it can be overridden by configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clinique, @jlaur,

I've implements the config for timezone in this commit.
Let me know if it's ok for you.
4281d5e

Laurent.

@lolodomo
Copy link
Contributor

The fix fails for me.
It worked just one time apparently because.i previously opened a session on the website but the next days it failed.

@lolodomo
Copy link
Contributor

While I installed 4.3.1, I updated again the linky bundle and it seems to work well yesterday and also today!
So maybe in my previous test, I did not take care and the previous jar was reloaded...

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments related to the time-zone commit. The I18 properties file should also be regenerated.

@lo92fr
Copy link
Contributor Author

lo92fr commented Jan 15, 2025

Hello @jlaur, Hello @lolodomo,

Any news on this ?

Thanks,
Laurent. @

@jlaur
Copy link
Contributor

jlaur commented Jan 15, 2025

Any news on this ?

My comments are resolved, but I have not reviewed this PR, so @lolodomo will be needed for finalizing the review and merging the PR.

@lolodomo
Copy link
Contributor

The major problem is that unfortunately this fix does not work well !
It can work one day after a fresh OH install and then does not work anymore. This is probably a problem of cookie or similar.
I remember that we had exactly the same issue with the previous fix ... until @lo92fr fixed something more.

Am I alone with this PR not working more than one day ?

@lo92fr
Copy link
Contributor Author

lo92fr commented Jan 15, 2025

The major problem is that unfortunately this fix does not work well ! It can work one day after a fresh OH install and then does not work anymore. This is probably a problem of cookie or similar. I remember that we had exactly the same issue with the previous fix ... until @lo92fr fixed something more.

Am I alone with this PR not working more than one day ?

Have to said that I'm not totally sure myself if the fix is ok or not.
I'm working on my production server with the linkyv2 branch, and have disconnection every 24 hours.
I was thinking it was because of the workflow change that i've maded on linkyv2 branch (linky v2 keep the connection opened, but main branch disconnect / reconnect at every 24 hours refresh), but finally perhaps not.

@lolodomo : what error do you have after one day, an http 500 Internal Error ?
Anything in the log ?

What I try so far if to make the refresh more frequent, I see that if I change the refresh frequence from 24h to 3h, I can trigger the error as weel after only 3 hours.

I've also try in this case to clear all cookie, and redo the connectionInit phase, but this don't seem sufficient to fix the error.
But in v2, when I hit the error, If i stop the thing, and restart it, the connection restart to work correctly.

So I thing there is something that expire after some session time, and stay in memory, and that is not reinitialized correctly.

I will continue to narrow done this issue in the next few days, and will tell you if I find something.

Laurent.

@lolodomo
Copy link
Contributor

what error do you have after one day, an http 500 Internal Error ?

{"message":"Internal server error. Please try again","code":"INTERNAL_SERVER_ERROR"}

@lo92fr
Copy link
Contributor Author

lo92fr commented Jan 26, 2025

what error do you have after one day, an http 500 Internal Error ?

{"message":"Internal server error. Please try again","code":"INTERNAL_SERVER_ERROR"}

Hello all, @lolodomo

Perhaps find a fix on this new error.
It seems that we need to call the getPrmInfo each time we update the data.
Today, we only do it when initializing the handler.

My assomption is that the new website implementation keep some state data, and invalidate them after a few hours.
This state data is certainly initialize when we call this getPrmInfo endpoint.

I've doned some test on v2 branch, seems to fix the problems on my side.
Will need to be tested also on this fix branch to be sure.

Laurent.

@lolodomo
Copy link
Contributor

lolodomo commented Feb 1, 2025

@lo92fr : can you please rebase your branch so that we can compile it again ?

- URL for data is now mes-mesures-prm and not mes-mesures.
- Dto format have changed : mainly merge data & date, field renaming, and moving.
- Some changes on date format.

Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
@lo92fr
Copy link
Contributor Author

lo92fr commented Feb 2, 2025

do it when initializing the handler.

My assomption

Helo @lolodomo,

Done the rebasing just right now.
But note that my fix from last week is not sufficient to totally fix our issues.
I've done some more modifications on the linkyv2 branch that seems to be promising.
I will try to backport them to fix branch this afternoon, or somewhere laster this week if I don't find time today.

Laurent.

@lolodomo
Copy link
Contributor

lolodomo commented Feb 2, 2025

I just build and deploy the last jar and yes you're right, it still does not work, always the same internal server error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New version of Enedis website,
5 participants