-
-
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
[fronius] Added inverter power, battery state of charge and PV solar yield #10757
Conversation
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
@trokohl Can you take a look? |
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"; |
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.
Actually constants should be all upper case. Would be awesome if you could fix all in this class.
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> |
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.
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> |
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.
<state pattern="%.2f W" readOnly="true"></state> | |
<state pattern="%.2f %unit%" readOnly="true"></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.
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?
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.
Are you sure your Item configuration is correct? Seems like the Item is updated from two different sources.
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.
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.
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 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?
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.
With 3.1.0-RC1 the localization issue is gone. See latest patch 76d8b02 .
Great that the local issue is gone! Your code doesn't build as it contains a checkstyle error. You could take a look at |
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>
3173781
to
73065c6
Compare
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 code doesn't compile as it contains a checkstyle error. You could take a look at target/code-analysis/report.html
.
} catch (IOException | IllegalStateException e) { | ||
errorMsg = e.getMessage(); | ||
logger.debug("Error running fronius request: {}", errorMsg); | ||
logger.error("Error running fronius request: {}", errorMsg); |
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.
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
@Nullable | ||
public Integer deviceId; |
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.
Syntactical sugar. Please check all.
@Nullable | |
public Integer deviceId; | |
public @Nullable Integer deviceId; |
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."); |
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 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."); |
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.
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; |
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.
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>
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! LGTM
…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>
…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>
…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>
…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>
This was added in openhab#10757 but the documentation was not updated. Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This was added in openhab#10757 but the documentation was not updated. Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This was added in openhab#10757 but the documentation was not updated. Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
…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>
…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>