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 : make use of DataConnect Enedis API #16355

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

Conversation

lo92fr
Copy link
Contributor

@lo92fr lo92fr commented Feb 1, 2024

Linky binding enhancement to support new DataConnect Enedis API

As view last week with Gael, this is a rewrite of the linky binding that use the official DataConnect Enedis API.
The use of this API will provide simpler authentification for the end user, as well as new functionnality like more granular data.

Description

This new binding version should offer right now the same functionnality that the old one.

This is WIP , will need on my side :

  • To fix compilation warning and code violation.

  • Do more in depth testing.

  • Would like to add more functionnality like :

    • New channel to expose Tarification, tempo Day,
    • Expose more granular data provide by this new API.
    • Importing historical value to persistance to enable graphing.
    • Add documentation on change between the old/new binding.

The evolution of linky binding was discuss as said with Gael in the following thread:
https://community.openhab.org/t/linky-use-the-api-not-the-http-webpage/129230

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/linky-binding-enhancement-to-support-new-dataconnect-enedis-api/153601/1

@clinique clinique changed the title Linkyv2 [WIP] Linkyv2 Feb 2, 2024
Copy link
Contributor

@clinique clinique left a comment

Choose a reason for hiding this comment

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

This is a first high level review of this work in progress.

*/
String formatAuthorizationUrl(String redirectUri);

String[] getAllPrmId();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would not a List<String> or Set<String> be more convenient ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

change in next commit

/**
* @param listener Adds the given handler
*/
public void setLinkyAccountHandler(LinkyAccountHandler accountHandler) {
Copy link
Contributor

Choose a reason for hiding this comment

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

LinkyAccountHandler could be passed by @Reference in the constructor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this class was remove from the new version after refactoring the code !

}

@Reference
protected void setHttpService(HttpService httpService) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same there

* The xxx manages the authorization with the Linky Web API. The servlet implements the
* Authorization Code flow and saves the resulting refreshToken with the bridge.
*
* @author Gaël L'hopital - Initial contribution *
Copy link
Contributor

Choose a reason for hiding this comment

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

Extraneous ' *'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next commit

*/

public class Customer {
@SerializedName("customer_id")
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) could save you from using @SerializedName in many places. Also these classes could become records.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gael,

I finally remove the setFieldNamingPolicy, because it was conflicting with the deserialization use on the old Web API.

*/

public class IntervalReading {
@SerializedName("value")
Copy link
Contributor

Choose a reason for hiding this comment

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

pointless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next commit


import java.util.HashMap;

import org.eclipse.jetty.jaas.spi.UserInfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

Needed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove in next commit

*/

public class TempoResponse extends HashMap<String, String> {
@java.io.Serial
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it seems to be need because i extend from HashMap

Copy link
Contributor

Choose a reason for hiding this comment

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

Your IDE could generate the serial

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but what's @java.io.Serial ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've remove this, it seems to work without this stuff.

</div>

</body>
</html>
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing crlf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next commit

@clinique clinique changed the title [WIP] Linkyv2 [WIP] Linky : make use of DataConnect Enedis API Feb 2, 2024
@clinique clinique added the enhancement An enhancement or new feature for an existing add-on label Feb 2, 2024
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/linky-communication-error/132889/39

@clinique
Copy link
Contributor

clinique commented Mar 4, 2024

Hello @lo92fr , are you still working on this ?

@lolodomo
Copy link
Contributor

lolodomo commented Mar 7, 2024

It was mentioned somewhere (community forum ?) that API limit will be reached with only few users using this API. If confirmed, this looks like a wrong approach.

PS: at the same time the current binding is now broken.

@clinique
Copy link
Contributor

clinique commented Mar 7, 2024

MyElectricalData seems to be alive and kicking as a replacement (they display serving ~2500 PDL). The good thing going this way is watherver provider is choosen the binding will be aligned with Enedis API, then be freed of website evolution and brackages.

@lo92fr
Copy link
Contributor Author

lo92fr commented Mar 7, 2024

MyElectricalData seems to be alive and kicking as a replacement (they display serving ~2500 PDL). The good thing going this way is watherver provider is choosen the binding will be aligned with Enedis API, then be freed of website evolution and brackages.

Hello all,

Sorry for my late response, but I was off home all February, with no access to my development computer.
So I make a pause on this, but I hope to have some time to work beginning on this weekend (but I also renovate my bathroom in my home, so don't know if I will have lot of time on it ...)

@clinique : I see your suggestion on pullrequest, I will address them as soon as possible.

Some comments around the api limitation to 5 call / seconds.
For me this is not really an issue for several reasons:

  • You need to call the api only once a day as the data is refresh only one time each day.
  • The plugin should cache data so it will only call the api when really need.
  • Other interesting things is that myelectricaldata have also some caching on their side, and so will call the Enedis API only when really need.

So it's not perfect, but if every user is not calling the API at the same exact time, it should be ok.

As someone already propose, I will also add some configuration so end user can change the endpoint from myelectricaldata to directly call Enedis API. I already put some code to handle the oauth configuration to do this. But It will need that the end user register officially to Enedis, and for this, the user will need to create a French law association. The is not a very complex process, but I think most user would not want to go this way ...

Best regards,
Laurent.

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* @author Gaël L'hopital - Initial contribution *
Copy link
Contributor

Choose a reason for hiding this comment

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

Extraneous '*'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next commit


/**
*
* @author Gaël L'hopital - Initial contribution *
Copy link
Contributor

Choose a reason for hiding this comment

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

Extraneous '*'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next commit

@lo92fr
Copy link
Contributor Author

lo92fr commented Mar 29, 2024

Hello all,

Just to keep you inform.
The association was created yesterday, and I've made the request to Enedis to get direct access to the API today.
As soon as I get it, i will finalized the modification on the addon.

2024-03-29 11_31_56-Souscrire – Enedis DataHub

Best regards,
Laurent.

@lolodomo
Copy link
Contributor

Ideally, we should keep an option for the users to choose between the original way with a direct connection to Enedis or the new way with a third-party.
PS: for your information, Gael just fixed the binding which is working again.

@lo92fr
Copy link
Contributor Author

lo92fr commented Apr 16, 2024

Hello @lolodomo,

Yes, you're right.
I will leave an option to toggle between direct Enedis connections, or through an third party gateway.

Laurent.

@lo92fr
Copy link
Contributor Author

lo92fr commented Apr 16, 2024

Hello all,

For information, I finalize to get a contract with Enedis last week.
So I should now be able to finalize the modification on the authentification part, and test this in the next week.

Laurent.

@lolodomo
Copy link
Contributor

I added the tag "work in progress" as "WIP" is still in the PR title.
Let us know when this is no more "work in progress".

@lolodomo lolodomo added the work in progress A PR that is not yet ready to be merged label May 25, 2024
@lo92fr
Copy link
Contributor Author

lo92fr commented Jun 4, 2024

Hello All,

I have a doubt about the Enedis direct implementations.
I made the required change to support it, and it seems ok on technical side.

But the matter is that Enedis think it as a central cloud service, not one deployed localy on every openhab user web server.
So I'm finally not sure they will agreed to validate the application to go in production mode...

image

@lo92fr lo92fr requested a review from clinique June 4, 2024 15:45
@lo92fr
Copy link
Contributor Author

lo92fr commented Jun 4, 2024

Hello Clinique,

I made a few commit this week, reviewing your comment.
And refactoring the binding a bit to support both myelectricalData and Enedis direct api call.

It seems to work ok, but still need to verify if Enedis will accept it to go in production this way, or if we need to have an intermediate platform to handle the consent / customer journey part.

Also, about TimeSeries, it seems great, but I prefer introduce this latter if it's ok for you.

If you have time, can you review the fixes so we can close the open conversations ?

Thanks,
Laurent.

@lo92fr
Copy link
Contributor Author

lo92fr commented Jun 5, 2024

Hello all,

for you information.
I've doned some test this morning with new openhab timeseries.
This is really a very cool new feature.

I was able to push consumption data, and also tempo day date to only one channel, with 2 year history for each.
After this, it is very simple to obtains graph like the one we can found on enedis site.

To give you a sample:

A consumption graph for one month, one value each day:
image

A tempo graph using the echart calendar :
image

Laurent.

public static final String YEAR_MINUS_1 = "yearly#lastYear";
public static final String YEAR_MINUS_2 = "yearly#year-2";

public static final String MAIN_IDENTITY = "main#Identity";
Copy link
Contributor

Choose a reason for hiding this comment

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

main#identity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix on next commit

*/
public static final String LINKY_SCOPES = Stream.of("am_application_scope", "default")
.collect(Collectors.joining(" "));
// "r:devices:*", "w:devices:*", "x:devices:*", "r:hubs:*",
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments will have to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix on next commit

*/

public class TempoResponse extends HashMap<String, String> {
@java.io.Serial
Copy link
Contributor

Choose a reason for hiding this comment

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

Your IDE could generate the serial

@lsiepel
Copy link
Contributor

lsiepel commented Aug 7, 2024

@lo92fr @clinique what is the state of this pr?

@lo92fr
Copy link
Contributor Author

lo92fr commented Aug 8, 2024

@lo92fr @clinique what is the state of this pr?

Hello Isiepel,

This is still work in progress.
There is two different provider / bridge in the new binding.

The first provider MyElectricaldata is working quite well, just needing some few more test, and some code cleanup.

The second provider is direct Enedis ApiConnection. This can't be use like this because it will need everyone to register to Enedis, that would not be possible easily. Other options will be to provide an alternative gateway like MyElectricaldata. But so far, I don't investigate these options.

Possibly, if we want to integrate this in next version, the easiest way to go will be to drop the direct Enedis bridge, and only keep the MyElectricaldata data bridge. This is how it works today on the home assistant implementation.

Laurent.

@lsiepel
Copy link
Contributor

lsiepel commented Aug 12, 2024

@lo92fr @clinique what is the state of this pr?

Hello Isiepel,

This is still work in progress. There is two different provider / bridge in the new binding.

The first provider MyElectricaldata is working quite well, just needing some few more test, and some code cleanup.

The second provider is direct Enedis ApiConnection. This can't be use like this because it will need everyone to register to Enedis, that would not be possible easily. Other options will be to provide an alternative gateway like MyElectricaldata. But so far, I don't investigate these options.

Possibly, if we want to integrate this in next version, the easiest way to go will be to drop the direct Enedis bridge, and only keep the MyElectricaldata data bridge. This is how it works today on the home assistant implementation.

Laurent.

Wdyt @clinique ?

@clinique
Copy link
Contributor

Yes, I think you should drop the Enedis part as it will more than likely not be used by anybody here.

@lo92fr lo92fr changed the title [WIP] Linky : make use of DataConnect Enedis API Linky : make use of DataConnect Enedis API Dec 18, 2024
Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
review handling of URL for api based bridge

Signed-off-by: Laurent ARNAL <[email protected]>
…ount

- add retry mechanisms to reconnect web bridge in case of errors

Signed-off-by: Laurent ARNAL <[email protected]>
Signed-off-by: Laurent ARNAL <[email protected]>
add some more info to docs

Signed-off-by: Laurent ARNAL <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on work in progress A PR that is not yet ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants