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

[senechome] Extend with additional channels, refactor and various improvements #10687

Merged
merged 6 commits into from
May 29, 2021

Conversation

eguib
Copy link
Contributor

@eguib eguib commented May 13, 2021

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

…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]>
@eguib eguib force-pushed the 10679_senechome_new_channels branch from f30a6fc to 8cb6f4e Compare May 13, 2021 20:45
eguib added 2 commits May 14, 2021 19:53
…"real" testdata from "vars.html"

Adjusted SenecHomeHandler#getSenecValue to support the full value range (int value parsing)

Signed-off-by: Erwin Guib <[email protected]>
@KorbinianP
Copy link
Contributor

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 👍

Copy link
Contributor

@KorbinianP KorbinianP left a 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.*;
Copy link
Contributor

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 👍

Comment on lines +306 to +324
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));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🥇

Comment on lines -353 to +404
updateState(channelGridPower.getUID(), new QuantityType<Power>(gridTotal, Units.WATT));
updateState(channelGridPower.getUID(), new QuantityType<>(gridTotal, Units.WATT));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the removed?

Copy link
Contributor Author

@eguib eguib May 22, 2021

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".

@eguib eguib requested a review from a team as a code owner May 22, 2021 20:41
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!

@kaikreuzer kaikreuzer merged commit 3875d2a into openhab:main May 29, 2021
@kaikreuzer kaikreuzer added this to the 3.1 milestone May 29, 2021
@kaikreuzer kaikreuzer added the enhancement An enhancement or new feature for an existing add-on label May 29, 2021
@wborn wborn changed the title [senechome] issue #10679: Extend with additional channels; refactor and various improvements [senechome] Extend with additional channels, refactor and various improvements Jun 22, 2021
computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this pull request Jul 13, 2021
…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]>
frederictobiasc pushed a commit to frederictobiasc/openhab-addons that referenced this pull request Oct 26, 2021
…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]>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
…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]>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
…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]>
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.

[SenecHome] Improvement: add more channels for: battery, MPP[x], temperature and wallbox
3 participants