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

[Units] Add MK⁻¹ unit alias #4433

Merged
merged 4 commits into from
Nov 4, 2024
Merged

Conversation

andrewfg
Copy link
Contributor

See discussion openhab/openhab-addons#17638 (comment)

Signed-off-by: AndrewFG [email protected]

@andrewfg andrewfg requested a review from a team as a code owner October 29, 2024 16:06
@andrewfg
Copy link
Contributor Author

@maniac103 for info..

@ccutrer
Copy link
Contributor

ccutrer commented Oct 29, 2024

Should we also be adding mirek as an alias? And perhaps changing the proper name of the unit to MK⁻¹ , with mired as the alias?

@andrewfg
Copy link
Contributor Author

^
I would support that.

@ccutrer
Copy link
Contributor

ccutrer commented Oct 30, 2024

LGTM

@andrewfg andrewfg requested a review from jlaur November 1, 2024 00:35
@lolodomo
Copy link
Contributor

lolodomo commented Nov 1, 2024

I followed the discussion and it looks good to me too.

@lolodomo
Copy link
Contributor

lolodomo commented Nov 1, 2024

If I have a String myUnit containing a unit, what is the code to use to check that is a unit in "mired" whatever the accepted symbol ?
If I use Units.MIRED.toString().equals(myUnit), this will probably work only with "mired" with the current code and only "MK⁻¹" when this PR is merged.

@andrewfg
Copy link
Contributor Author

andrewfg commented Nov 1, 2024

If I have a String myUnit containing a unit, what is the code to use to check that is a unit in "mired" whatever the accepted symbol ?

Umm. From memory I believe it is the following. .. But perhaps I should add a Junit test to confirm that works?

Unit unit = QuantityType.valueOf(yourString).getUnit();

EDIT: whereby "yourString" has to contain a number rather than a pattern..

Signed-off-by: AndrewFG <[email protected]>
@andrewfg
Copy link
Contributor Author

andrewfg commented Nov 1, 2024

@lolodomo I just added the Junit test (it passes).

PS and the code for checking a pattern match would be..

String pattern = "%.0f mired";
boolean isOk = false;
try {
    isOk = Units.MIRED == QuantityType.valueOf(String.format(pattern, 123)).getUnit();
} catch (Exception e) {
}

@ccutrer
Copy link
Contributor

ccutrer commented Nov 1, 2024

Or UnitUtils.parseUnit if you only have the unit, without a scalar for a full quantity

@lolodomo
Copy link
Contributor

lolodomo commented Nov 1, 2024

Or UnitUtils.parseUnit if you only have the unit, without a scalar for a full quantity

Oh yes, looks better, thank you.

Copy link
Member

@holgerfriedrich holgerfriedrich left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@holgerfriedrich holgerfriedrich merged commit 591d8d9 into openhab:main Nov 4, 2024
5 checks passed
@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature of the Core label Nov 4, 2024
@holgerfriedrich holgerfriedrich added this to the 4.3 milestone Nov 4, 2024
@andrewfg andrewfg deleted the mirek branch November 6, 2024 15:48
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 of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants