-
-
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
[senechome] Extend with additional channels, refactor and various improvements #10687
Conversation
…handling (openhab#10679). Merged PR 9535 (rename batteryState to system state) - charge/discharge energy/current/voltage/min/maxCellVoltage/load cycles per battery pack - current/power/voltage per MPP - liveHouseConsumption/livePowerGenerator - battery,case,MCU temperature - wallbox1: state, charging power/current, liveEnergy - improve error handling, catch malformed JSON exception to prevent crashing the binding - merged PR: 9535 (rename batteryState to systemState) - renamed SenecHomeLimitation to SenecHomePower and added more channels - refactored SenecHomeHandler to reduce code duplication (added some nice helper methods) Signed-off-by: Erwin Guib <[email protected]>
f30a6fc
to
8cb6f4e
Compare
Signed-off-by: Erwin Guib <[email protected]>
…"real" testdata from "vars.html" Adjusted SenecHomeHandler#getSenecValue to support the full value range (int value parsing) Signed-off-by: Erwin Guib <[email protected]>
Hello @eguib Thank you so much for your contribution! So many more data points 😊 I will have a closer look into the code, but looking into my work week I can't promise a quick response. A quick overview looks really nice! Do you want to add yourself as code owner? I would be happy 👍 |
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 really like your changes. Would you like to add yourself as code owner?
@@ -12,6 +12,7 @@ | |||
*/ | |||
package org.openhab.binding.senechome.internal; | |||
|
|||
import static org.openhab.binding.senechome.internal.SenecHomeBindingConstants.*; |
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.
Very nice! Easy way to improve readability below 👍
protected <Q extends Quantity<Q>> void updateQtyState(String channelName, String senecValue, int scale, | ||
Unit<Q> unit) { | ||
updateQtyState(channelName, senecValue, scale, unit, null); | ||
} | ||
|
||
protected <Q extends Quantity<Q>> void updateQtyState(String channelName, String senecValue, int scale, | ||
Unit<Q> unit, @Nullable BigDecimal divisor) { | ||
Channel channel = getThing().getChannel(channelName); | ||
if (channel == null) { | ||
return; | ||
} | ||
BigDecimal value = getSenecValue(senecValue); | ||
if (divisor != null) { | ||
value = value.divide(divisor, scale, RoundingMode.HALF_UP); | ||
} else { | ||
value = value.setScale(scale, RoundingMode.HALF_UP); | ||
} | ||
updateState(channel.getUID(), new QuantityType<Q>(value, unit)); | ||
} |
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.
🥇
updateState(channelGridPower.getUID(), new QuantityType<Power>(gridTotal, Units.WATT)); | ||
updateState(channelGridPower.getUID(), new QuantityType<>(gridTotal, Units.WATT)); |
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 was the 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.
Java type inference: the compiler can "gues" the correct type from generics definition (because WATT is defined as Unit<Power>
).
This "feature" is also used on the various "updateQtyState" methods I introduced. The QuantityType infers its generic type from the "unit".
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, thank you!
…actor and various improvements (openhab#10687) * [senechome] Extend with additional channels; refactor; improve error handling (openhab#10679). Merged PR 9535 (rename batteryState to system state) - charge/discharge energy/current/voltage/min/maxCellVoltage/load cycles per battery pack - current/power/voltage per MPP - liveHouseConsumption/livePowerGenerator - battery,case,MCU temperature - wallbox1: state, charging power/current, liveEnergy - improve error handling, catch malformed JSON exception to prevent crashing the binding - merged PR: 9535 (rename batteryState to systemState) - renamed SenecHomeLimitation to SenecHomePower and added more channels - refactored SenecHomeHandler to reduce code duplication (added some nice helper methods) Signed-off-by: Erwin Guib <[email protected]>
…actor and various improvements (openhab#10687) * [senechome] Extend with additional channels; refactor; improve error handling (openhab#10679). Merged PR 9535 (rename batteryState to system state) - charge/discharge energy/current/voltage/min/maxCellVoltage/load cycles per battery pack - current/power/voltage per MPP - liveHouseConsumption/livePowerGenerator - battery,case,MCU temperature - wallbox1: state, charging power/current, liveEnergy - improve error handling, catch malformed JSON exception to prevent crashing the binding - merged PR: 9535 (rename batteryState to systemState) - renamed SenecHomeLimitation to SenecHomePower and added more channels - refactored SenecHomeHandler to reduce code duplication (added some nice helper methods) Signed-off-by: Erwin Guib <[email protected]>
…actor and various improvements (openhab#10687) * [senechome] Extend with additional channels; refactor; improve error handling (openhab#10679). Merged PR 9535 (rename batteryState to system state) - charge/discharge energy/current/voltage/min/maxCellVoltage/load cycles per battery pack - current/power/voltage per MPP - liveHouseConsumption/livePowerGenerator - battery,case,MCU temperature - wallbox1: state, charging power/current, liveEnergy - improve error handling, catch malformed JSON exception to prevent crashing the binding - merged PR: 9535 (rename batteryState to systemState) - renamed SenecHomeLimitation to SenecHomePower and added more channels - refactored SenecHomeHandler to reduce code duplication (added some nice helper methods) Signed-off-by: Erwin Guib <[email protected]>
…actor and various improvements (openhab#10687) * [senechome] Extend with additional channels; refactor; improve error handling (openhab#10679). Merged PR 9535 (rename batteryState to system state) - charge/discharge energy/current/voltage/min/maxCellVoltage/load cycles per battery pack - current/power/voltage per MPP - liveHouseConsumption/livePowerGenerator - battery,case,MCU temperature - wallbox1: state, charging power/current, liveEnergy - improve error handling, catch malformed JSON exception to prevent crashing the binding - merged PR: 9535 (rename batteryState to systemState) - renamed SenecHomeLimitation to SenecHomePower and added more channels - refactored SenecHomeHandler to reduce code duplication (added some nice helper methods) Signed-off-by: Erwin Guib <[email protected]>
As I got a new "SENEC.Home V3 hybrid duo" some months ago I started playing around with OpenHab and here is the result. I added a lot of additional channels, esp. because I wanted to monitor the MPP values (as in my situation MPP1 and MPP3 have the same number of solar panel, but sometimes quite different solar production ...).
Also added wallbox monitoring as Senec itself does not provide any historic data regarding the wallbox (except the current day values there is no data available at all).
While working with the code I refactored SenecHomeHandler in a similar way as @KorbinianP with PR #9535 (with some additional nice functionality to handle different scaling of the data). Also "merged" the renaming of batteryState to systemState as the new name reflects the correct meaning of the channel. Also did this because merge of the 2 PR will result in merge conflicts due the refactring done on both branches. With the approval of the author this PR could become a replacement/enhancement for #9535.
I also hit the senec error described with issue #10025. I catched the parent exception JsonParseException because I have seen different "strange" malformed/broken communications resulting in both JsonIOException and JsonSyntaxException.
=> with this error handling the binding run "stable" for several weeks.
I attach my snapshot build, would be interesting to test it with other Senec variants (V2, V3 ...) I tried to code as defensive as possible, but it is not clear to me how the different senec machines will react ...
One must consider the following:
Looking forward to some feedback. Please be gracious, it is my first contribution ;-)
org.openhab.binding.senechome-3.1.0-SNAPSHOT.jar.zip
Fixes #10679