-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: main
Are you sure you want to change the base?
Conversation
This is the binding for local connection to the Ferroamp Energy System Signed-off-by: Örjan Backsell <[email protected]>
Changes done in FerroampHandlerFactory.java Signed-off-by: Örjan Backsell <[email protected]>
Hi @lsiepel , |
There was a problem hiding this 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.
@@ -484,12 +480,10 @@ | |||
<module>org.openhab.voice.watsonstt</module> | |||
<module>org.openhab.voice.whisperstt</module> | |||
</modules> | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20241014
Done
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
bundles/org.openhab.binding.ferroamp/src/main/resources/OH-INF/thing/ferroamp.xml
Outdated
Show resolved
Hide resolved
Please, see each Conversion for latest answers. |
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]>
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. |
There was a problem hiding this 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.
...hab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EhubParameters.java
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsmParameters.java
Outdated
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsoParameters.java
Outdated
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/SsoParameters.java
Outdated
Show resolved
Hide resolved
...ab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampHandler.java
Outdated
Show resolved
Hide resolved
|
||
private void startMqttConnection() throws InterruptedException { | ||
try { | ||
TimeUnit.SECONDS.sleep(10); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
...ding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampConfiguration.java
Outdated
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsoParameters.java
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsmParameters.java
Show resolved
Hide resolved
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]>
Please see above, I think I have answered all of your suggestions. Btw, Thanks! |
Changes done in: FerroampHandler.java FerroampMqttCommunication.java README.md Signed-off-by: Örjan Backsell <[email protected]>
2024111 |
Done changes in: FerroampConfiguration.java FerroampHandler.java FerroampMqttCommunication.java README.md Signed-off-by: Örjan Backsell <[email protected]>
2024115 |
There was a problem hiding this 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.
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsmParameters.java
Show resolved
Hide resolved
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsoParameters.java
Show resolved
Hide resolved
@@ -484,12 +480,10 @@ | |||
<module>org.openhab.voice.watsonstt</module> | |||
<module>org.openhab.voice.whisperstt</module> | |||
</modules> | |||
|
There was a problem hiding this comment.
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]>
Hi, The actually wrong things in text in README is just embarrassing for me, I should have seen them. It seems to be similar problem with bundles/pom. So this is over my knowledge, Please help ;-) Br Basse |
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.
That is because the first link points to an old commit (notice the guid and dif at the link parameters). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another pass.
| soc | Number:Percentage | R | System State of Check | State of the system | | ||
| soh | Number:Percentage | R | System State of Health | | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| 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 | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null, "); | |
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null"); |
There was a problem hiding this comment.
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
...nhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/EsmParameters.java
Show resolved
Hide resolved
|
||
final MqttBrokerConnection ferroampConnection = new MqttBrokerConnection(ferroampConfig.hostName, | ||
FerroampBindingConstants.BROKER_PORT, false, false, ferroampConfig.userName); | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return immediate
logger.debug("Problems with startMqttConnection()"); | |
logger.debug("Problems with startMqttConnection()"); | |
return; |
There was a problem hiding this comment.
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
Objects.requireNonNull(ferroampConnection, "MqttBrokerConnection ferroampConnection cannot be null"); | ||
if (ferroampConnection.connectionState().toString().equals("DISCONNECTED")) { |
There was a problem hiding this comment.
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.
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")) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text + exit immediate
logger.debug("Problem connection to MqttBroker"); | |
logger.debug("Not connected to the MqttBroker"); | |
return |
There was a problem hiding this comment.
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
try { | ||
channelUpdate(); | ||
updateStatus(ThingStatus.ONLINE); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try { | |
channelUpdate(); | |
updateStatus(ThingStatus.ONLINE); | |
updateStatus(ThingStatus.ONLINE); | |
try { | |
channelUpdate(); |
There was a problem hiding this comment.
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]>
20241125 |
Changes done in FerroampHandler.java Signed-off-by: Örjan Backsell <[email protected]>
Hi, |
This is the binding for local connection to the Ferroamp Energy System