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

[ferroamp] Binding for Ferroamp 20241010 #17536

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

Conversation

basse04
Copy link
Contributor

@basse04 basse04 commented Oct 10, 2024

This is the binding for local connection to the Ferroamp Energy System

This is the binding for local connection to the Ferroamp Energy System

Signed-off-by: Örjan Backsell <[email protected]>
@basse04 basse04 requested a review from a team as a code owner October 10, 2024 10:17
Changes done in FerroampHandlerFactory.java

Signed-off-by: Örjan Backsell <[email protected]>
@lsiepel lsiepel added enhancement An enhancement or new feature for an existing add-on new binding If someone has started to work on a binding. For a new binding PR. and removed enhancement An enhancement or new feature for an existing add-on labels Oct 10, 2024
@basse04
Copy link
Contributor Author

basse04 commented Oct 10, 2024

Hi @lsiepel ,
I have had an system-disc crach, mine SSD got full without telling me before it went totally out of order. So I had to install an entire new OS ( Linux Mint 21.3) and everything else I need. So I thought that the best then was to also create a new branch ( ferroamp_v4).
There was initially problems with Maven, I had an old version installed that mvn locally liked but not the checks as above, this is now solved.
And then a question regarded to that, mvn locally complained and said I shold use Maven 3.8.1, I have now installed Maven 3.8.8 and it seems to work, do you think I should use any later version or will this one be fine?
BR Basse

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

As it had some passes before i keep this short. Left comments mainly looking at the readme. Some suggestions need to be adapted on multiple places. The binding is improving, so good to see progress.

bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
@@ -484,12 +480,10 @@
<module>org.openhab.voice.watsonstt</module>
<module>org.openhab.voice.whisperstt</module>
</modules>

Copy link
Contributor

Choose a reason for hiding this comment

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

these are unexpected. Only the change on line 145 is expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, don't know, but I can see them also in mine fork and in openhab/openhab-addons

Copy link
Contributor

Choose a reason for hiding this comment

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

I do know and they are unexpected :-)
Please revert all changes and only change the line 145. You can copy paste the contents of:
https://raw.githubusercontent.com/openhab/openhab-addons/refs/heads/main/bundles/pom.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241014
Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Please check again, there are still unexpected changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was fxied before, but somehow the unexpected changes came back.


The following configuration parameters are available.

| Name | Type | Description | Default | Required | Advanced |
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the thing-types.xml the eso and esm parameters are missing.

Would be nice if these setting scould be auto detected by the binding instead of manually configuring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in README.
I will think about auto detect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eso and Esm modules seems not to be so very common so I think we leave these 2 as optional in configuration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still wondering if you can in someway detect if SSO1-4, ESM or ESO is present by using the API ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241115
Changes done regarded to SSO's, they are now detected automatically.
Eso and Esm modules seems not to be so very common so I think we leave these 2 as optional in configuration, and the very same for the battery.

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 also auto detect eso en esm? It doesnt really matter if they are common or not.

@basse04
Copy link
Contributor Author

basse04 commented Oct 24, 2024

Please, see each Conversion for latest answers.
I have also done a new ferroamp.properties
Br Basse

Changes done in README.md, 20241010

Örjan Backsell <[email protected]>

Signed-off-by: Örjan Backsell <[email protected]>
Done changes in EhubParameters.java, FerroampBindingConstants.java,
FerroampChannelConfiguration.java, ferroamp.xml, README.md

Signed-off-by: Örjan Backsell <[email protected]>
Changes done in:
EsmParameters.java
EsoParameters.java
ferroamp.xml
FerroampBindingConstants.java
FerroampChannelConfiguration.java
README.md
SsoParameters.java

Signed-off-by: Örjan Backsell <[email protected]>
Changes done in README.md

Signed-off-by: Örjan Backsell <[email protected]>
Changes done, Please see Reply...regarded to each conversion

Signed-off-by: Örjan Backsell <[email protected]>
Changes done in FerroampHandler.java

Signed-off-by: Örjan Backsell <[email protected]>
Please, see each Conversion for latest answers

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Oct 25, 2024

Hi, @lsiepel, finally have I found a solution for the, for me very embarrassing misstake to forgot about the first part of sign-off in one commit.
But now it seems to be solved, puh :-)
I wish you a nice weekend!
Br Basse

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Another round with suggested improvements. Hopefully this will lead to more improvements. Please verify the changes you make match the asked changes or comment what you did and why, as that helps to speed up.

Have not yet looked at too much java code. I did notice quit verbose json handling with element indices and all that. Might be perfectly sane, but usually when you have json, it is best to use proper DTO's. But first let's fix the already made comments.

Oh yes, another question, did you consider to use channel groups ? They seem a perfect fit for the sso, as you could define 1 set of channels and duplicate it for each group.

bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved

private void startMqttConnection() throws InterruptedException {
try {
TimeUnit.SECONDS.sleep(10);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this sleep ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241107
It seems like the broker in the Ferroamp EnergyHub need some time to start sending.
There will be an complaining about that MqttBrokerConnection localSubscribeConnection in method getMQTT in ferroampMqttComminication is null otherwise

Copy link
Contributor

@lsiepel lsiepel Nov 10, 2024

Choose a reason for hiding this comment

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

I would suggest that two lines of getMQTT is moved to this startMqttConnection() method, as these lines should only be fired once. and not for each subscription?!

        localSubscribeConnection.start();
        localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password);

getMQTT should also be renamed to subscribeTopic (or something similar)

Besides the above, this sleep still bothers me. First i looked at the MQTT bindings and could not find anything similar, but they are totally different in setup. Adn then i asked myseldf why is this no subbindingof mqtt just like the others? Like mqtt.ferroamp did you consider this and can you share some insights why not?

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 have problems with that it seems like I have to wait for broker to start sending. (I have no system on mine own so I use one at a friend, might be a reason for the delay, but thats just a guess).
Anyhow, the sleep was an emergency solution to handle this delay, but I think I found another solution, Please have a look in FerroampHandler.java.

I have changed the name to getSubscribedTopic.

Sleep and scheduler.execute(() -> {.... is both now taken away due to that both were regarded to my tries to handle the delays.

When I started with this binding did I found some solution( don't remember which ) simiilar to this one. I have then down the road also seen the mqtt.x solution, but I thought that I shall continue to do it the way I have started, so actually no reasons, other then I think that has been a way for me as nopro to get any kind of a working and for me understandable solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is ok for now, lets first finish most of the binding, but i think we will need to come back to this before we can merge. Let's not mix all review comments together. I think this should be a subbinding of mqtt like: mqtt.ferroamp
@jlaur do you know a discussion/rule/definition on why and when it should be a subbinding of mqtt?

Changes done in:
EhubJsonElements.java
EsmJsonElements.java
EsoJsonElements.java
ferroamp.properties
FerroampBindingConstants.java
FerroampChannelConfiguration.java
FerroampConfiguration.java
FerroampHandler.java
FerroampMqttCommunication.java
SsoJsonElements.java
thing-types.xml

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 7, 2024

Please see above, I think I have answered all of your suggestions. Btw, Thanks!
I will have a look at the suggestions left asap
Br Basse

Changes done in:
FerroampHandler.java
FerroampMqttCommunication.java
README.md

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 11, 2024

2024111
Done some changes, Please see each for info.
Br Basse

Done changes in:
FerroampConfiguration.java
FerroampHandler.java
FerroampMqttCommunication.java
README.md

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 15, 2024

2024115
Done some changes, Please see each for info.
Br Basse

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Sorry to say, but reviewing this is hard and taking much time. I know you are doing your best and i hope you continue to advance with this binding. Progress is slow as it seems some kind of lottery to see changes fixed, reverted or not fixed.
Let me know if i can assist fixing a specific problem with your workflow.

bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
bundles/org.openhab.binding.ferroamp/README.md Outdated Show resolved Hide resolved
@@ -484,12 +480,10 @@
<module>org.openhab.voice.watsonstt</module>
<module>org.openhab.voice.whisperstt</module>
</modules>

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was fxied before, but somehow the unexpected changes came back.

Done changes in:
FerroampChannelConfiguration.java, regarded CHANNEL_APPARENTPOWER
thing-types.xml, regarded CHANNEL_APPARENTPOWER
FerroampHandler.java, regarded Annotation warnings
FerroampMqttCommunication.java, regarded Annotation warnings
README.md, regarded pointed out changes

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 21, 2024

Hi,
first, Thank you so very much for your patience and of course for all very good advices :-)

The actually wrong things in text in README is just embarrassing for me, I should have seen them.
Regarded to a lot of strange things happen seems to be, me not very knowledgeable to how Github is coworking with my IDE.
Ex. About the XXParameters.java files so thought I that they were deleted with commit, so I made a new try but I am not sure that they actually are deleted. Please see commit above.

It seems to be similar problem with bundles/pom.
If I look in: https://github.com/openhab/openhab-addons/pull/17536/files/00301172ca0250e3d8043da3a4ee3ec7d0ad7643#diff-c6d3c87f68d7ef315e8d25c56c4cd6182c7a06b1ee9bb3f3b5db977e238250c9 can I see these two lines.
But if I look in: https://github.com/basse04/openhab-addons/edit/ferroamp_v4/bundles/pom.xml?pr=%2Fopenhab%2Fopenhab-addons%2Fpull%2F17536 they are'nt there.

So this is over my knowledge, Please help ;-)

Br Basse

@lsiepel
Copy link
Contributor

lsiepel commented Nov 21, 2024

Hi, first, Thank you so very much for your patience and of course for all very good advices :-)

The actually wrong things in text in README is just embarrassing for me, I should have seen them. Regarded to a lot of strange things happen seems to be, me not very knowledgeable to how Github is coworking with my IDE. Ex. About the XXParameters.java files so thought I that they were deleted with commit, so I made a new try but I am not sure that they actually are deleted. Please see commit above.

They are deleted now. What IDE do you use? I have been using several IDE's and about all of them (1) detect the deleted file, (2) put them on a list of changes that you can (3) commit and (4) push. As soon as the changes are pushed to your v4 branch, they are also visible on this PR.

It seems to be similar problem with bundles/pom. If I look in: https://github.com/openhab/openhab-addons/pull/17536/files/00301172ca0250e3d8043da3a4ee3ec7d0ad7643#diff-c6d3c87f68d7ef315e8d25c56c4cd6182c7a06b1ee9bb3f3b5db977e238250c9 can I see these two lines. But if I look in: https://github.com/basse04/openhab-addons/edit/ferroamp_v4/bundles/pom.xml?pr=%2Fopenhab%2Fopenhab-addons%2Fpull%2F17536 they are'nt there.

That is because the first link points to an old commit (notice the guid and dif at the link parameters).
Most recent files are here: #17536 and there you can see the pom.xml still has many unwanted changes.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

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

Another pass.

Comment on lines 129 to 130
| soc | Number:Percentage | R | System State of Check | State of the system |
| soh | Number:Percentage | R | System State of Health | |
Copy link
Contributor

Choose a reason for hiding this comment

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

Number:Percentage does not exists, please revert to Number:Dimensionless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Changed in README.md

@@ -177,7 +176,7 @@ The following configuration parameters are available.
| eso-current-battery | Number:ElectricCurrent | R | Eso Current on Battery Side | Measured on battery side |
| eso-battery-energy-produced | Number:Energy | R | Eso Battery Energy Produced | Total energy produced by ESO, i.e total energy charged |
| eso-battery-energy-consumed | Number:Energy | R | Eso Battery Energy Consumed | Total energy consumed by ESO, i.e total energy discharged |
| eso-soc | Number:Dimensionless | R | Eso State of Charge | State of Charge for ESO |
| eso-soc | Number:Percentage | R | Eso State of Charge | State of Charge for ESO |
Copy link
Contributor

Choose a reason for hiding this comment

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

Number:Percentage does not exists, please revert to Number:Dimensionless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Changed in README.md

Comment on lines 189 to 190
| esm-soh | Number:Percentage | R | Esm System State of Health | State of Health for ESM |
| esm-soc | Number:Percentage | R | Esm System State of Charge | State of Charge for ESM |
Copy link
Contributor

Choose a reason for hiding this comment

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

Number:Percentage does not exists, please revert to Number:Dimensionless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Changed in README.md

@@ -113,7 +113,7 @@ private void pollTask() {
logger.debug("Problem connection to MqttBroker");
}

Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null");
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null, ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert

Suggested change
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null, ");
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Method pollTask() is changed so these lines are deleted


final MqttBrokerConnection ferroampConnection = new MqttBrokerConnection(ferroampConfig.hostName,
FerroampBindingConstants.BROKER_PORT, false, false, ferroampConfig.userName);

Copy link
Contributor

Choose a reason for hiding this comment

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

Before exiting this method you should set the thing state to unknown.
The async pollTask should later on set it to offline or online.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Changes done to method initialize() in FerroampHandler.java

try {
startMqttConnection();
} catch (InterruptedException e) {
logger.debug("Problems with startMqttConnection()");
Copy link
Contributor

Choose a reason for hiding this comment

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

return immediate

Suggested change
logger.debug("Problems with startMqttConnection()");
logger.debug("Problems with startMqttConnection()");
return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Added as descibed, line 117

Comment on lines 110 to 111
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null");
if (ferroampConnection.connectionState().toString().equals("DISCONNECTED")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The requireNonNull can be used to 'convert' a nullable variable to a non-null.
In this case you can use a local variable. Using a local variable fixes this issue as a local variable cannot be cahnged between the check and the usages. A variable at a wider scope (class level) could be changed by a different thread in between the if check and the usage. I know this is a race condition that actually never happens, but it can happen so the compiler complains about it and that is why we need to fix it.

Suggested change
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null");
if (ferroampConnection.connectionState().toString().equals("DISCONNECTED")) {
FerroampConnection ferroampConnection = this.ferroampConnection;
if (ferroampConnection == null || ferroampConnection.connectionState().toString().equals("DISCONNECTED")) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Still struggling with this. I think I understand what you describe but I have still not figure out how to solve it.
And I don't understand about line 110, FerroampConnection ferroampConnection = this.ferroampConnection; should I make a new Class FerroampConnection?
I have so far used Class MqttBrokerConnection for ferroampConnection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241126
Please see my latest changes in FerroampHandler.java
Changes done in:
method initialize, line 97
method pollTask, line 113
method startMqttConnection, line 136

Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null");
if (ferroampConnection.connectionState().toString().equals("DISCONNECTED")) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
logger.debug("Problem connection to MqttBroker");
Copy link
Contributor

Choose a reason for hiding this comment

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

Text + exit immediate

Suggested change
logger.debug("Problem connection to MqttBroker");
logger.debug("Not connected to the MqttBroker");
return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Changes done as described

Comment on lines 118 to 121
try {
channelUpdate();
updateStatus(ThingStatus.ONLINE);

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
try {
channelUpdate();
updateStatus(ThingStatus.ONLINE);
updateStatus(ThingStatus.ONLINE);
try {
channelUpdate();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

20241125
Please see changes in method pollTask()

Changes done in:
ferroamp.properties
FerroampConfiguration.java
FerroampHandler.java
FerroampMqttCommunication.java
README.md
thing-types.xml

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 25, 2024

20241125
Commited some more changes, Please see each for info.
Maybe have I found the reason for the not deleted files.
I'm using Eclipse and I just found a possible reason, you have to mark the files as Untracked and then Commit them. This is described as "This will essentially do the same as git rm --cached."
Just to be sure, is the /bundles/pom.xml OK now?
And then just another question: Where do I find /bundles/pom.xml in Eclipse Package Explorer
Many questions but I know I will get very good answers :-)
BR Basse

Changes done in FerroampHandler.java

Signed-off-by: Örjan Backsell <[email protected]>
@basse04
Copy link
Contributor Author

basse04 commented Nov 26, 2024

Hi,
done some changes in FerroampHandler.java, Please see the actual conversion.
Br Basse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new binding If someone has started to work on a binding. For a new binding PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants