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

Convert units for bounds when compiling full state descriptions #3132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Oct 24, 2022

See the comments in StateDescriptionFragmentImpl.merge for a full description of the problem and solution.

@ccutrer ccutrer requested a review from a team as a code owner October 24, 2022 22:52
ccutrer added a commit to ccutrer/openhab-addons that referenced this pull request Oct 25, 2022
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
ccutrer added a commit to ccutrer/openhab-addons that referenced this pull request Oct 25, 2022
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
@ccutrer ccutrer force-pushed the convert-bounds-in-state-descriptions branch 2 times, most recently from 8ac94ab to 815b0d6 Compare October 25, 2022 22:27
lolodomo pushed a commit to openhab/openhab-addons that referenced this pull request Oct 27, 2022
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
@J-N-K
Copy link
Member

J-N-K commented Nov 13, 2022

I feel that - especially considering #2283 - we should discuss what get's merged and what SHOULD take precedence (not necessarily what we have now).

@ccutrer
Copy link
Contributor Author

ccutrer commented Nov 13, 2022

+1. I hadn't even considered how multiple-linking would affect this. Definitely needs thought through

Signed-off-by: Cody Cutrer <cody@cutrer.us>
@ccutrer ccutrer force-pushed the convert-bounds-in-state-descriptions branch from 4083b5f to 86d0b43 Compare November 29, 2022 16:19
@ccutrer
Copy link
Contributor Author

ccutrer commented Nov 29, 2022

I force-pushed and rebased since part of this PR was extracted to its own PR and merged. remaining files have not changed since the last version of this PR, and discussion is still pending. Just wanted to clean it up so when we get back to it in the future it won't be as confusing.

@wborn wborn changed the title convert units for bounds when compiling full state descriptions Convert units for bounds when compiling full state descriptions Nov 30, 2022
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/uom-default-units-and-consequences/142360/75

borazslo pushed a commit to borazslo/openhab-mideaac-addon that referenced this pull request Jan 8, 2023
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Feb 28, 2023
So that other pieces of openhab can know what unit it's going to be,
without it having a value yet. Importantly, any necessary conversion
that need to be applied to the other portion of the state description -
min, max, and step.

See also openhab/openhab-core#3132

Signed-off-by: Cody Cutrer <cody@cutrer.us>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/binding-improvements-best-practice/146664/2

@J-N-K
Copy link
Member

J-N-K commented May 13, 2023

@ccutrer Now that we have proper UoM support, could you rebase and check if this is still working as you expect? If so, I can review it.

@J-N-K J-N-K self-assigned this May 13, 2023
@J-N-K J-N-K added enhancement An enhancement or new feature of the Core awaiting feedback labels May 13, 2023
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Thanks, mostly looks good. Can you also add. Test that includes Number:Dimensionless? We have seen a lot of unexpected issues with the in the past, it would be good to have that covered.

It would also be great if you could rebase, so we are sure there is nothing wrong with the new unit handling.

Comment on lines +224 to +226

if (minimum == null && (newValue = fragment.getMaximum()) != null) {
minimum = new QuantityType(newValue, newUnit).toInvertibleUnit(oldUnit).toBigDecimal();
Copy link
Member

Choose a reason for hiding this comment

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

While this works, I would prefer a more explicit style here like:

Suggested change
if (minimum == null && (newValue = fragment.getMaximum()) != null) {
minimum = new QuantityType(newValue, newUnit).toInvertibleUnit(oldUnit).toBigDecimal();
BigDecimal newMinimum = fragment.getMaximum();
if (minimum == null && newMinimum != null) {
minimum = new QuantityType(newMinimum, newUnit).toInvertibleUnit(oldUnit).toBigDecimal();

The same of course also applies to the other locations.

@boehan
Copy link
Contributor

boehan commented Jul 5, 2023

If I understand this correctly, bounds (and step) use the unit of the state pattern if set. However, this would probably have no effect, if the pattern is set to %unit%. Thus, binding developers would have to predefine to be able to set correct bounds, which does not allow the default state description to follow system default units (I assume bounds always use unit of pattern set by the binding).
Wouldn't it be clearer, if bounds (and step) could be set with appropriate unit (which could even differ from the one set in the pattern)? And potentially use the approach proposed here as a fallback if no dedicated unit is set?

@ccutrer
Copy link
Contributor Author

ccutrer commented Jul 17, 2023

I've not had time to look at this again, and likely won't in the near future. I do agree with @boehan that it would make more sense if the StateDescription carried the unit with it as a QuantityType, rather than assuming the consumer knows how to parse the unit out of the format pattern (if provided). But I suspect that would be a significant breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants