-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Fix group calculations to use GroupItem's system unit #4563
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@mherwege for info.. |
This comment was marked as outdated.
This comment was marked as outdated.
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Show resolved
Hide resolved
@mherwege while testing this, I discovered that the JUnit assertion test values are physically WRONG. e.g. the sum of 23.54 °C plus 89 °C plus 122.41 °C is absolutely NOT 234.95 °C .. rather it is 781.24 °C .. this assumes that the three absolute Kelvin values must be summed. => So this really provokes the question about what we are really trying to achieve here? Do we want a) just the sum of three numbers, or b) the sum of three physical temperatures?
|
Look at the PR I already linked several times. This is on purpose. The second and third arguments are interpreted ad differential values, not absolute values. And that’s what makes sense, as most would expect that adding 20 °C to 20 °C gives 40°C. And with the way it is done, it does. It also works for Fahrenheit, which is not the same scale as Kelvin or Celsius. This problem is only there if the 0 point of the respective units is not the same. |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Ok. Got it. I just committed support for the following..
|
Signed-off-by: Andrew Fiddian-Green <[email protected]>
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.core/src/test/java/org/openhab/core/internal/i18n/TestKelvinProvider.java
Outdated
Show resolved
Hide resolved
...re/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java
Outdated
Show resolved
Hide resolved
...re/src/test/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunctionTest.java
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
What about the following approach: Create a new method in openhab-core/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java Line 585 in ce37425
It should be something like:
You then call this method instead of This will then be different from when you simply do the calculation in a rule, because there only the first argument is treated as ABSOLUTE. But I don't think this kind of logic applies in groups anyhow. |
@mherwege please calm down. As you say add is a relative function. It is based on the zero point offset of the initial unit. So in the case of Celsius it is a relative add. And in the case of Kelvin (and most other zero based units) the add function is at the same time both relative and absolute. So..
|
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Absolutely true, but my worry is the different results depending on the unit used. And that is not logical. QuantityType calculations are meant to give the same result, whatever the unit. And of course that cannot be true for invertible units, which is a special case. And that's what we try to solve that by converting to the group item base unit to make the result at least predictable. But if it breaks the rule of having the same result within the same dimension, whatever the unit, that is not acceptable. And the rule is broken because of the conversion to the base unit. Add now does not do a relative add anymore, whatever the unit. |
Honestly, I am pretty calm on this. I am just trying to achieve the best possible result. That's why I keep on questioning things. If we don't do that now, I know we hit issues at some point in time and we will have to find other workarounds again. |
We just need to add the following text to the readme and JavaDoc; then everything clear :) The
See. Perfectly logical. :)
|
This is not what the current add method in QuantityType does. Within the group arithmetic functions, because you first convert all arguments to the base unit, you get (assuming base unit is K): |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Are you sure? I would expect a result of 40 °C ??? |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
@mherwege I made a commit just now that should hopefully reflect our final agreement. |
Signed-off-by: Andrew Fiddian-Green <[email protected]>
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <[email protected]>
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
...b.core/src/main/java/org/openhab/core/library/types/QuantityTypeArithmeticGroupFunction.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
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: Andrew Fiddian-Green <[email protected]>
@mherwege thanks for approving the PR. Unfortunately I had to revert your proposal from |
Depends on openhab/openhab-core#4563 Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Signed-off-by: Andrew Fiddian-Green <[email protected]>
Fixes #4562
There was a bug whereby the calculations over a GroupItem's set of member Items are based on the Unit of the first member in the set. There are two problems: a) the order of the Items in the set is not fixed, and b) the Unit of the first member Item is also not definitive to the Unit of the expected result. Therefore these calculations do produce variable and unexpected results.
This PR fixes the bug by normalising the calculations over the group's set of member Items so that all calculations are based on the System Unit of the GroupItem's base Item.
Furthermore this PR allows conversion between non- inverted and inverted Units so invertible conversions (e.g. Kelvin <=> Mirek) are supported.
Signed-off-by: Andrew Fiddian-Green [email protected]