-
-
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
[iammeter] Iammeter Binding initial contribution #8252
Conversation
Travis tests were successfulHey @lewei50, |
1 similar comment
Travis tests were successfulHey @lewei50, |
Did you finish making all changes from the old PR? |
yes. |
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.
Your changes from the other PR look good! Here is my detailed feedback.
There are some formatting issues. You can view them with mvn spotless:check -Dspotless.check.skip=false
and fix them with mvn spotless:apply
.
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterConfiguration.java
Show resolved
Hide resolved
Travis tests were successfulHey @lewei50, |
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ing.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080Channel.java
Outdated
Show resolved
Hide resolved
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
...ng.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterWEM3080TChannel.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
Travis tests were successfulHey @lewei50, |
Travis tests were successfulHey @lewei50, |
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.
LGTM
Since this is a new binding, another maintainer needs to review your code before it can be merged.
In the meantime, you can fix some formatting issues. You can view them with mvn spotless:check -Dspotless.check.skip=false
and fix them with mvn spotless:apply
.
Please also update your sign-offs in the commit messages. The real name is required. See https://www.openhab.org/docs/developer/contributing.html#sign-your-work
Travis tests were successfulHey @lewei50, |
Travis tests were successfulHey @lewei50, |
Thanks for your help,I'v re-do the sign-off push. |
Travis tests were successfulHey @lewei50, |
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.
Thanks for your contribution. The code isn't to complex, but you might need look into how to improve some modelling related to the different types of devices. See my comment. If you have any questions or need some help feel free to ask.
.project
Outdated
@@ -0,0 +1,17 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
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 remove this file
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.
file removed.
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.
You've removed the wrong file 😉 This file is at the root, you removed the file in the binding. That file should not be removed.
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
protected void thingStructureChanged(String channelPrefix) { |
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.
This is not right. You should model the different types as different things. So in the xml you would see 2 things, 1 with all channels and 1 with the limited set of channels. You can then create 2 different classes, or maybe create 2 classes that each parse the specific data. and in the handler factory you can than pass that specific class to this handler based on the specific thing created.
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.
thanks for your advice,I have separated those into 2 thingHandler now.
...ab.binding.iammeter/src/main/java/org/openhab/binding/iammeter/internal/IammeterHandler.java
Outdated
Show resolved
Hide resolved
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, | ||
"Communication error with the device: " + e.getMessage()); | ||
} catch (JsonSyntaxException je) { | ||
logger.warn("Invalid JSON when refreshing source {}: {}", getThing().getUID(), je.getMessage()); |
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.
In this case the status should probaly also be set to OFFLINE.
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.
status set.
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 don't see the updateStatus
here. Is it done somewhere else?
If you are able to fix the last review comments on short notice we'll be able to add this binding to openHAB 2.5.9. Otherwise it will go to openHAB 3.0. |
thanks for all your advices,I am working on fix them recently,and fixed them finally. |
Travis tests have failedHey @lewei50, |
Travis tests were successfulHey @lewei50, |
1 similar comment
Travis tests were successfulHey @lewei50, |
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.
Where almost there. Just some comments related to you additional changes.
.project
Outdated
@@ -0,0 +1,17 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
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.
You've removed the wrong file 😉 This file is at the root, you removed the file in the binding. That file should not be removed.
bundles/org.openhab.binding.iammeter/src/main/resources/ESH-INF/thing/3080.xml
Outdated
Show resolved
Hide resolved
<channel id="importenergy" typeId="importenergy"/> | ||
<channel id="exportgrid" typeId="exportgrid"/> | ||
</channels> | ||
<config-description> |
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.
Because all configuration parameters for the 2 things are the same you can also put the configuration in a config/config.xml
and reference here to that config. See some other bindings, search for config-description-ref
.
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.
<label>Iammeter Power Meter 3080T</label> | ||
<description>3 phases PowerMeter for Iammeter 3080T Binding</description> | ||
<channel-groups> | ||
<channel-group id="powerPhaseA" typeId="powerPhaseGroupA" /> |
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.
You only need 1 group powerPhaseGroup
. And for each group set label and description here:
<channel-group id="powerPhaseA" typeId="powerPhaseGroupA" /> | |
<channel-group id="powerPhaseA" typeId="powerPhaseGroup" > | |
<label>Power Phase A</label> | |
<description>Power phase 1 for Iammeter device</description> | |
</channel-group> |
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.
String content = ""; | ||
InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); | ||
|
||
String response = HttpUtil.executeUrl(httpMethod, url, stream, null, TIMEOUT_MS); |
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 stream
is an empty String. Do you need to send something or does it also work to use:
String response = HttpUtil.executeUrl(httpMethod, url, stream, null, TIMEOUT_MS); | |
String response = HttpUtil.executeUrl(httpMethod, url, TIMEOUT_MS); |
Same applies to the other handler
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.
both changed.
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, | ||
"Communication error with the device: " + e.getMessage()); | ||
} catch (JsonSyntaxException je) { | ||
logger.warn("Invalid JSON when refreshing source {}: {}", getThing().getUID(), je.getMessage()); |
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 don't see the updateStatus
here. Is it done somewhere else?
JsonElement iammeterDataElement = new JsonParser().parse(response); | ||
JsonObject iammeterData = iammeterDataElement.getAsJsonObject(); | ||
String keyWord = "Datas"; | ||
if (iammeterData.has("Datas") && iammeterData.has("SN")) { | ||
String groups[] = { "powerPhaseA", "powerPhaseB", "powerPhaseC" }; | ||
for (int row = 0; row < groups.length; row++) { | ||
String gpName = groups[row]; | ||
List<Channel> chnList = getThing().getChannelsOfGroup(gpName); | ||
for (IammeterWEM3080Channel channelConfig : IammeterWEM3080Channel.values()) { | ||
Channel chnl = chnList.get(channelConfig.ordinal()); | ||
if (chnl != null) { | ||
State state = getDecimal(iammeterData.get(keyWord).getAsJsonArray().get(row) | ||
.getAsJsonArray().get(channelConfig.ordinal()).toString(), channelConfig.getUnit()); | ||
updateState(chnl.getUID(), state); | ||
} | ||
} |
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.
Related to the class splitting. I didn't intend for you to completely copy paste the code as it duplicates a lot of code. Better make an abstract
base class with all the logic and let it call methods to do the specific code. The code I selected here would be in the sub class. The method would get the response as parameter. You can make the method getDecimal
protected
(better rename it getQuantityState
probably`.
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.
abstract class made.
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.
abstract class made.
ScheduledFuture<?> refreshJob = this.refreshJob; | ||
if (refreshJob != null && !refreshJob.isCancelled()) { | ||
refreshJob.cancel(true); | ||
refreshJob = 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.
You need to set the field to null:
refreshJob = null; | |
this.refreshJob = 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.
changed.
Travis tests were successfulHey @lewei50, |
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Also-by: Yang Bo<[email protected]> Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Travis tests were successfulHey @lewei50, |
2 similar comments
Travis tests were successfulHey @lewei50, |
Travis tests were successfulHey @lewei50, |
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.
Just some clean up comments.
Can you also run mvn spotless:apply
on your binding to make sure the style complies, otherwise it might break the build (this changed recently).
*/ | ||
|
||
@NonNullByDefault | ||
public class IammeterBaseHandler extends BaseThingHandler { |
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.
public class IammeterBaseHandler extends BaseThingHandler { | |
public abstract class IammeterBaseHandler extends BaseThingHandler { |
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.
added.
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.
codes reformated using mvn spotless:apply.
String url = "http://" + config.username + ":" + config.password + "@" + config.host + ":" + config.port | ||
+ "/monitorjson"; | ||
String content = ""; | ||
InputStream stream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); |
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.
This is not used anymore and can be removed.
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.
removed.
|
||
resolveData(response); | ||
|
||
// JsonElement iammeterDataElement = new JsonParser().parse(response); |
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.
Can you remove this commented out code.
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.
removed.
} | ||
} | ||
|
||
protected void resolveData(String response) { |
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.
By maing this class abstract you can also make this method abstract:
protected void resolveData(String response) { | |
protected abstract void resolveData(String response); |
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.
Signed-off-by: lewei50 <[email protected]>
Signed-off-by: lewei50 <[email protected]>
Travis tests have failedHey @lewei50, |
1 similar comment
Travis tests have failedHey @lewei50, |
Travis tests were successfulHey @lewei50, |
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.
LGTM
Signed-off-by: Yang Bo <[email protected]>
Signed-off-by: Yang Bo <[email protected]>
Signed-off-by: Yang Bo <[email protected]>
Initial contribution,Add support for Iammeter devices in Openhab.
Iammeter devices provides real-time readings of power meter over Wi-Fi.
The Iammeter binding is make data visualized in openhab system.
this binding had tested locally.
sorry that I closed PR 7799 accidentally and don't know how to open it again,so I opened this PR to continue my progress.
sorry to bother you with this.