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

Maintain curated list of units for a given dimension #4082

Closed
andrewfg opened this issue Feb 6, 2024 · 4 comments · Fixed by openhab/openhab-webui#2312
Closed

Maintain curated list of units for a given dimension #4082

andrewfg opened this issue Feb 6, 2024 · 4 comments · Fixed by openhab/openhab-webui#2312

Comments

@andrewfg
Copy link
Contributor

andrewfg commented Feb 6, 2024

That is why I was thinking of a drop down plus 'custom' input. Both one and % could be in the standard dropdown (with unit-hint preselected or % if unit-hint == null). The other standard options would be ppM, ppB, and dB. Any other unit, including those with milli, kilo, prefixes etc. could still be entered via the 'custom' input..

This makes sense for Dimensionless. But if you check the list of 'standard' units, you will notice it actually only lists exceptions not covered out of the box by the libraries. For instance, it creates mm/h, but km/h comes from the libraries. So the code you link is by no way exhaustive. Also, it would have to be created manually in the UI code.
I think what is need is a way to query a set of units for a given dimension through the REST API from core, and then show that list. That would make sure things are in sync with core and there are no two places to maintain it. Again, I think this goes beyond the scope of this (and the linked UI) PR. It is probably worth creating a specific enhancement request issue for it.

Originally posted by @mherwege in #4079 (comment)

@J-N-K
Copy link
Member

J-N-K commented Feb 6, 2024

This is not possible. How do you select which combinations are shown? Take for instance velocity:

  • length can be expressed as mm, cm, dm, m, km, in, ft, mi (which are common, every metric prefix like M, G, T is also valid for m)
  • time can be expressed as ms, s, min, h, d, m, y (which are common, every metric prefix is also valid for s)

Any combination of these units is a valid velocity unit, at least 48 different units if we only take the most common ones (although probably in/y or km/ms don't make much sense).

If at all a curated list of units should be available in Main UI, but core should not present a subset of available units.

@mherwege
Copy link
Contributor

mherwege commented Feb 6, 2024

If at all a curated list of units should be available in Main UI, but core should not present a subset of available units.

Fair enough. And I was aware of the problem of selecting what to show. The reason to consider putting a curated list in core is that it would allow to maintain everything about units in one place, together with the unit types. I am happy to move this to the ui and maintain it there though.

Can this issue be reformulated (not REST API) and moved to the webui repository?

@andrewfg andrewfg changed the title Rest Api to return list of units for a given dimension Maintain curated list of units for a given dimension Feb 7, 2024
@andrewfg
Copy link
Contributor Author

andrewfg commented Feb 7, 2024

Can this issue be reformulated (not REST API) and moved to the webui repository?

I changed the title, but I am not authorized to move it..

florian-h05 pushed a commit to openhab/openhab-webui that referenced this issue Mar 1, 2024
Closes openhab/openhab-core#4082.

This PR adds:

1. A curated list of units to show as a drop-down list when creating a Number item with dimension.
2. The possibility to use a different default unit on item creation than the system default unit.
3. The ability to change unit and state description for items.
4. The ability to use the `unitHint` provided by channel types for "Link channel to Item" -> "Create a new Item".

By default, the system default unit (for the configured measurement system) will be shown when editing or creating an item.

`units.js` contains a number of frequently used units by dimension and measurement system.
These will be available in a autosuggest dropdown list.
It is still possible to not select from the list and use any other string as a unit.

All units for the dimension in `units.js` will be in the dropdown list, but they will be sorted by measurement system. If the measurement system is set to US, imperial units will appear higher in the list.
Units that have not explicitely been listed as SI or US will always appear higher.

When typing a unit that is not in the curated list, a longer list will be used for autocompletion that considers allowed prefixes to base units and constructs all combinations.

`units.js` also contains a field to set a different default unit on item creation than the system default unit.

With openhab/openhab-core#4079, the REST API of channel types will provide a unit hint if defined in the binding channel types.
If such information is available, this PR adds support for this to be the the suggested unit.
If that information is unavailable, the UI will fall back to behavious described above.

---------

Also-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
@florian-h05
Copy link
Contributor

Can someone please close this issue? I have merged the UI PR, but since I have no issue managment rights on the core repo, this issue was not closed automatically.

@J-N-K J-N-K closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants