Skip to content

Conversation

lo92fr
Copy link
Contributor

@lo92fr lo92fr commented Aug 11, 2025

Support for reading index instead of basic value,

Description

This PR is about to get consumption index from the api instead of consumption value.
With consumption index, we will be able to dispatch the consumption to a specific tarif, and have graph where you can see consumption of different time area in the day.

For exemple, it will support tarif like:
Heure pleine / Heure creuse.
Tempo tariff with 6 dispatch cadran : Red, White, Blue & HP/HC.

And the first version only implement EnedisWeb gateway.

@lo92fr
Copy link
Contributor Author

lo92fr commented Aug 11, 2025

For exemple, you will obtains graph like this one:

image

@lsiepel lsiepel marked this pull request as draft August 11, 2025 20:05
@lsiepel lsiepel requested a review from Copilot August 11, 2025 20:05
@lsiepel lsiepel added the enhancement An enhancement or new feature for an existing add-on label Aug 11, 2025
Copilot

This comment was marked as outdated.

lo92fr added 2 commits August 31, 2025 18:22
…ournisseur and distributor dispatch like heure creuse / heure pleine or tempo tarif).

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr lo92fr force-pushed the features/linky-index branch from 1fc1544 to a5b1bfc Compare August 31, 2025 16:22
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
@wborn wborn added the work in progress A PR that is not yet ready to be merged label Sep 8, 2025
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
remove unnecessary code after last fixes

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
…the binding

Signed-off-by: Laurent ARNAL <laurent@clae.net>
- Will create channel dynamically to represent each available tarif.
- Will split the dataset result to the bound of tarif change.
- Will update each time series accordly.
- Graph will be able to display silmutaneous tarif on the same graph.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
… set to 0.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
add verification for tarif change

Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr
Copy link
Contributor Author

lo92fr commented Sep 21, 2025

Hello @lsiepel,

Can I ask you to relaunch a Copilot review on this PR.
There is many code change / refactoring since previous Copilot review, and so It will be more easy to start from a fresh analysis.

Also, I think the PR is now ready for final review.
I've made bunch of test this week, and everything seems to work no well.

@lolodomo, @clinique: fill free to test on your side, and make any comment if need.

Laurent

@lsiepel lsiepel requested a review from Copilot September 21, 2025 14:56
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 12 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@lo92fr
Copy link
Contributor Author

lo92fr commented Sep 21, 2025

Thanks @lsiepel,

I fixed the errors from the last copilot review.

Laurent.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lsiepel
Copy link
Contributor

lsiepel commented Sep 21, 2025

Is this still WIP? If not, please remove the label.

@lo92fr
Copy link
Contributor Author

lo92fr commented Sep 21, 2025

Is this still WIP? If not, please remove the label.

No, this is ready for merge.
I don't think I have permission to remove the tag.
Can you do it for me ?

Thanks

@lsiepel lsiepel removed the work in progress A PR that is not yet ready to be merged label Sep 21, 2025
@jlaur jlaur changed the title [linky] Support for reading index instead of basic value, [linky] Add support for reading index instead of basic value Sep 25, 2025
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

Review part 1 of 2, all except README and class ThingLinkyRemoteHandler

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

Review of README

Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr
Copy link
Contributor Author

lo92fr commented Oct 12, 2025

Hello @lolodomo,

Thanks for the review.
I've pushed the fixes.

@lo92fr lo92fr requested a review from lolodomo October 12, 2025 12:40
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

Review changes in class ThingLinkyRemoteHandler until line 902

Comment on lines 539 to 545
*
* @param channels
* @param chanTypeUid
* @param channelGroup
* @param channelName
* @param channelLabel
* @param channelDesc
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the parameters or comment them fully.
Same for other methods in that class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@lolodomo lolodomo Oct 19, 2025

Choose a reason for hiding this comment

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

If you provide Javadoc, you have to do it fully, that means mentioning all parameters and describe them.
You have now added a description to parameters but you only mentioned some of them and not all.

So either provide all parameters (with a description) or provider no parameters at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I've completed all existing javadoc with all parameters

Comment on lines +553 to +555
if (getThing().getChannel(channelUid) != null) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this test before line 550.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@lolodomo lolodomo Oct 19, 2025

Choose a reason for hiding this comment

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

You did not move it as expected. My idea was to do this test even before building the channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this make sense. So in this order:

private void addChannel(List channels, ChannelTypeUID chanTypeUid, String channelGroup, String channelName,
String channelLabel, @nullable String channelDesc) {
ChannelUID channelUid = new ChannelUID(this.getThing().getUID(), channelGroup, channelName);

    if (getThing().getChannel(channelUid) != null) {
        return;
    }

    ChannelBuilder builder = ChannelBuilder.create(channelUid).withType(chanTypeUid).withLabel(channelLabel);

    if (channelDesc != null) {
        builder = builder.withDescription(channelDesc);
    }

    Channel channel = builder.build();

    if (channels.contains(channel)) {
        return;
    }

    channels.add(channel);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that was my suggestion.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr
Copy link
Contributor Author

lo92fr commented Oct 18, 2025

Hello @lolodomo,

I've pushed the fixes for your review of this morning.
Sorry for all the typo in the comments of ThingLinkyRemoteHandler, I've check the full file, and will try to better check next time.
You will have to review my comment about label for dynamic channel, we can eventually prefix the label with the group name.
But not sure it is very a good thing as channel label are in french (coming from the data), and group are in English.

Laurent.

@lo92fr lo92fr requested a review from lolodomo October 18, 2025 13:38
@lolodomo
Copy link
Contributor

lolodomo commented Oct 19, 2025

You will have to review my comment about label for dynamic channel, we can eventually prefix the label with the group name.
But not sure it is very a good thing as channel label are in french (coming from the data), and group are in English.

Yes, you're probably right. I have commented as a response to the original comment.

I would prefer to avoid the ERROR log level for the unexpected index mode.
Edit: ERROR level is already (wrongly at my opinion) used in this class, so this is just one more. So I don't know if it has to be changed or not.

Look at my 3 comments that are not yet marked as resolved.
I will finish the review today (last part of changes in class ThingLinkyRemoteHandler).

IntervalReading[] iv = meterReading.baseValue;

logData(iv, "Last day", DateTimeFormatter.ISO_LOCAL_DATE, Target.LAST);
return iv != null && iv.length != 0 && iv[iv.length - 1] != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously, it was checked that the last value is not NaN.
You changed that to only check if the value is not null.
Is it because the API changed and NaN is no more happening ?

Copy link
Contributor

Choose a reason for hiding this comment

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

If I correctly remember, the API returns NaN for the consumption for yesterday in the early hours of the day. We detected that to know that the currently retrieved data is not yet ready and that we will have to retry later in the day.

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, I'm not totally sure of the reason of this change.
It's perhaps related to the previous comment.
I will need more time to check it, and be sure I don't brake anything.

if (!isDataLastDayAvailable(meterReading)) {
logger.debug("Data including yesterday are not yet available");
return null;
return meterReading;
Copy link
Contributor

@lolodomo lolodomo Oct 19, 2025

Choose a reason for hiding this comment

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

I am not sure of the impact of this change.
If I correctly remember, returning null was intentional and was a trigger that we don't have the data yet.
Can you explain please.

Copy link
Contributor

@lolodomo lolodomo Oct 19, 2025

Choose a reason for hiding this comment

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

If I correctly remember, returning null when data is missing was to not store any data in the cache and then to be sure that the API will be requested again the next hour.

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 remembered have introduce this because data for new index are never available on last day.
Always have a one day difference for this index,

I've also remembered have ask Enedis team about this behavior, but I far as I remember, have no response from there so far.

And yes, previously returning null was a way to be sure to re-request the data in next hours to be sure to have them.
So I definitively need to do some more check on this point to be sure that I've not broke something

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using a different method for indexes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes perhaps a solution, or handle the return value differently base on the face we are handling index or consumption value

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've finally revert this change.
I need it at the first place because the entry for meterReading array have 1095 entries, but when reading index we have only 1094 entries, and so the last value of the array was always empty when reading index.

But at the same time, I've done some modification in MeterReading on commit (925585e / review data array bound when using index).
This modification allocate only 1094 entries in the array when we are in index mode.
So with this modification, isDataLastDayAvailable return correctly even in IndexMode.

So the hack on ThingLinlyRemoteHandler don't have any reason to persist !

I've done some test, and everything works ok like this.

Laurent

@lo92fr
Copy link
Contributor Author

lo92fr commented Oct 19, 2025

You will have to review my comment about label for dynamic channel, we can eventually prefix the label with the group name.
But not sure it is very a good thing as channel label are in french (coming from the data), and group are in English.

Yes, you're probably right. I have commented as a response to the original comment.

I would prefer to avoid the ERROR log level for the unexpected index mode. Edit: ERROR level is already (wrongly at my opinion) used in this class, so this is just one more. So I don't know if it has to be changed or not.

Look at my 3 comments that are not yet marked as resolved. I will finish the review today (last part of changes in class ThingLinkyRemoteHandler).

I've finally remove the prefix on channel Label.
This will end up with something like this:

image

About the Error log level, not sure to understand what you want ?
As said, this condition it not really like to occur.
So what will be the good way to handle it:

  • Return silently without logging an error (not sure that is a good thing).
  • Change log level to something else that error.
  • throw an exception, and toggle the thing to offline indicating an internal error ?
    Let me know.

About the 3 last comments, i'm currently looking at them.
Can take a little time as I've will have to check what happen in the different cases.

Laurent.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr
Copy link
Contributor Author

lo92fr commented Oct 19, 2025

@lolodomo,

I've push the changed about this morning review.
For the 3 comments about the null return and the NaN check, have to said that I'm not currently totally sure it's safe.
I will make more review on it, and will come back later this week we a more detailed answer.

Laurent

@lo92fr lo92fr requested a review from lolodomo October 19, 2025 14:29
We don't need anymore this modification, as was already fixed by commit * review data array bound when using index (925585e
) on MeterReading.

Signed-off-by: Laurent ARNAL <laurent@clae.net>
@lo92fr
Copy link
Contributor Author

lo92fr commented Oct 20, 2025

Hello @lolodomo,

See my comment about the two remaining point.
I revert the code to the old one.

Laurent.

…ly support index

Signed-off-by: Laurent ARNAL <laurent@clae.net>
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants