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

[fronius] Added inverter power, battery state of charge and PV solar yield #10757

Merged
merged 6 commits into from
Jul 11, 2021

Conversation

THKDev
Copy link
Contributor

@THKDev THKDev commented May 24, 2021

  • add missing field of solar yield (PV)
  • add flow data of inverter power
  • add flow data of battery state of charge

@THKDev THKDev requested a review from trokohl as a code owner May 24, 2021 13:20
@kaikreuzer kaikreuzer added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Jun 5, 2021
@fwolter
Copy link
Member

fwolter commented Jun 5, 2021

@trokohl Can you take a look?

@trokohl
Copy link

trokohl commented Jun 5, 2021

looks good

@@ -47,6 +48,7 @@
public static final String PowerFlowpGrid = "powerflowchannelpgrid";
public static final String PowerFlowpLoad = "powerflowchannelpload";
public static final String PowerFlowpAkku = "powerflowchannelpakku";
public static final String PowerFlowpPv = "powerflowchannelppv";
Copy link
Member

Choose a reason for hiding this comment

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

Actually constants should be all upper case. Would be awesome if you could fix all in this class.

Suggested change
public static final String PowerFlowpPv = "powerflowchannelppv";
public static final String POWER_FLOW_P_PV = "powerflowchannelppv";

@@ -196,6 +199,30 @@
<description>Battery Power ( + charge, - discharge )</description>
<state pattern="%.2f W" readOnly="true"></state>
</channel-type>
<channel-type id="pPv">
<item-type>Number</item-type>
<label>Solar plant power</label>
Copy link
Member

Choose a reason for hiding this comment

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

Words in labels should be capitalized (except prepositions and so on). See https://www.openhab.org/docs/developer/bindings/thing-xml.html#formatting-labels-and-descriptions

<item-type>Number</item-type>
<label>Solar plant power</label>
<description>Current solar plant power</description>
<state pattern="%.2f W" readOnly="true"></state>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<state pattern="%.2f W" readOnly="true"></state>
<state pattern="%.2f %unit%" readOnly="true"></state>

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 tried the thing with the %unit% but got some strange behavior.

thing-types.xml looks like

	<channel-type id="inverter1Soc">
		<item-type>Number:Dimensionless</item-type>
		<label>Inverter 1 State of Charge</label>
		<description>Inverter 1 State of Charge</description>
		<state pattern="%.1f %unit%" readOnly="true"></state>
	</channel-type>

Code looks like (getSoc() returns double)

new QuantityType<>(inverters.get(number).getSoc(), Units.PERCENT);

Debugger

NumberQuantity = "91.5999984741211 %"
value = 91.5999984741211
unit = "%"
scale = "RELATIVE"

Output switching like this

[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'FroniusSymoInverter_Inverter1StateofCharge' changed from 950999984741211 % to 95 %
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'FroniusSymoInverter_Inverter1StateofCharge' changed from 95 % to 949000015258789 %
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'FroniusSymoInverter_Inverter1StateofCharge' changed from 9169999694824219 % to 915999984741211 %

What do i miss?

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure your Item configuration is correct? Seems like the Item is updated from two different sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some more investigation shows the following behavior.

i18n.config

:org.apache.felix.configadmin.revision:=L"5"
language="de"
measurementSystem="SI"
service.pid="org.openhab.i18n"
timezone="Europe/Berlin"

server locale

LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

Running the openhab server with these settings will result in messed up values like "19563232421875,00" instead of "1956,32".

Running the server with the LC_CTYPE set to en_GB.UTF-8 will result in the correct values "1956.32" but in the wrong number format (point instead of comma).

bash> locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

bash> LC_CTYPE=en_GB.UTF-8 ./start_debug.sh

So it looks like an issue with the localization of "QuantityType". I think the whole localization should respect the browser languague instead of the server locale.

Copy link
Member

Choose a reason for hiding this comment

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

I can hardly belive this behavior is caused by the locale setting. Maybe it's only a symptom. Did you try this with a fresh installation of OH or on another system?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With 3.1.0-RC1 the localization issue is gone. See latest patch 76d8b02 .

@fwolter
Copy link
Member

fwolter commented Jun 30, 2021

Great that the local issue is gone! Your code doesn't build as it contains a checkstyle error. You could take a look at target/code-analysis/report.html.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
…s should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
…ils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

Your code doesn't compile as it contains a checkstyle error. You could take a look at target/code-analysis/report.html.

Comment on lines 205 to 207
} catch (IOException | IllegalStateException e) {
errorMsg = e.getMessage();
logger.debug("Error running fronius request: {}", errorMsg);
logger.error("Error running fronius request: {}", errorMsg);
Copy link
Member

Choose a reason for hiding this comment

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

Bindings should only log to error if something severe happened, like the detection of a bug in your code. This could be debug as you catch an IOException. See this link for a description of the log levels: https://www.openhab.org/docs/developer/guidelines.html#f-logging

Comment on lines 26 to 27
@Nullable
public Integer deviceId;
Copy link
Member

Choose a reason for hiding this comment

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

Syntactical sugar. Please check all.

Suggested change
@Nullable
public Integer deviceId;
public @Nullable Integer deviceId;

Comment on lines 152 to 154
private MeterRealtimeResponseDTO getMeterRealtimeData(final String ip, final Integer deviceId) {
Objects.requireNonNull(ip, "IP address must be set in the configuration.");
Objects.requireNonNull(deviceId, "Device ID must be set in the configuration.");
Copy link
Member

Choose a reason for hiding this comment

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

This will throw an unchecked exception, which will crash your binding. You could throw a custom exception and catch it in the calling method.

private PowerFlowRealtimeResponse getPowerFlowRealtime(String ip) {
String location = FroniusBindingConstants.POWERFLOW_REALTIME_DATA.replace("%IP%", StringUtils.trimToEmpty(ip));
private PowerFlowRealtimeResponse getPowerFlowRealtime(final String ip) {
Objects.requireNonNull(ip, "IP address must be set in the configuration.");
Copy link
Member

Choose a reason for hiding this comment

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

See above. Throw custom exception. Please check all.

…StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
Signed-off-by: THKDev <THKDev@users.noreply.github.com>

import org.apache.commons.lang3.StringUtils;
Copy link
Member

Choose a reason for hiding this comment

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

Since we want to get rid of Apache Commons, can you replace this with native Java code? See #7722.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
@fwolter fwolter added rebuild Triggers Jenkins PR build and removed rebuild Triggers Jenkins PR build labels Jul 10, 2021
Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@fwolter fwolter merged commit 1e8be24 into openhab:main Jul 11, 2021
@fwolter fwolter added the enhancement An enhancement or new feature for an existing add-on label Jul 11, 2021
@fwolter fwolter added this to the 3.2 milestone Jul 11, 2021
computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this pull request Jul 13, 2021
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
frederictobiasc pushed a commit to frederictobiasc/openhab-addons that referenced this pull request Oct 26, 2021
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
splatch pushed a commit to ConnectorIO/openhab-addons that referenced this pull request Dec 13, 2021
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
jimtng added a commit to jimtng/openhab-addons that referenced this pull request Mar 1, 2022
This was added in openhab#10757 but the documentation was not updated.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
jimtng added a commit to jimtng/openhab-addons that referenced this pull request Mar 1, 2022
This was added in openhab#10757 but the documentation was not updated.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
jimtng added a commit to jimtng/openhab-addons that referenced this pull request Mar 2, 2022
This was added in openhab#10757 but the documentation was not updated.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
splatch pushed a commit to ConnectorIO/openhab-addons that referenced this pull request Apr 23, 2022
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

Signed-off-by: Łukasz Dywicki <luke@code-house.org>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
…yield (openhab#10757)

* [fronius] add battery state of charge and PV yield.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] Actually constants should be all upper case. Words in labels should be capitalized (except prepositions and so on). Use %unit% placeholder.

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* Revert "[fronius] fixed checkstyle error; removed some warnings (eg. StringUtils)"

This reverts commit 73065c6

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] fixed checkstyle error

Signed-off-by: THKDev <THKDev@users.noreply.github.com>

* [fronius] removed org.apache.commons.lang3.StringUtils

Signed-off-by: THKDev <THKDev@users.noreply.github.com>
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.

None yet

4 participants