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

Set Defaut State Presentation for items not linked to channel #4071

Closed
dilyanpalauzov opened this issue Jan 27, 2024 · 27 comments · Fixed by #4175
Closed

Set Defaut State Presentation for items not linked to channel #4071

dilyanpalauzov opened this issue Jan 27, 2024 · 27 comments · Fixed by #4175
Labels
enhancement An enhancement or new feature of the Core

Comments

@dilyanpalauzov
Copy link
Contributor

The current logic for implicit state presentation is explained at openhab/openhab-webui#2251 (comment):

  1. If a pattern is found in the label of the sitemap element, use it.
  2. If a pattern is found in the label of the item, use it.
  3. If a pattern is found in the linked channel, use it
  4. If the linked channel is without pattern but is for string or number, use respectively %s and %.0f as pattern
  5. If still not found, do not display any value

I suggest extending the above logic, for items not linked to channels:

  • of type DateTime to use implicit [%s], spelling NULL when the value is NULL
  • of type String, as above
  • of type Number, if the unit can be determined by specialization of type Number:<dimension> use %.0f the unit. If unit cannot be guessed, use %.0f.

The latter logic should be applied also to Group:Number:<dimension>, Group:Number:<dimension>:<function>, Group:Number and Group:Number:<function>.

So if a user does not want to see the current value, the user can explicitly add [].

See also #3835 and openhab/openhab-webui#2251.

@dilyanpalauzov dilyanpalauzov added the enhancement An enhancement or new feature of the Core label Jan 27, 2024
@rkoshak
Copy link

rkoshak commented Jan 29, 2024

The unit should always be guessable. Calling getUnit() on the QuantityType will give you the current unit being used every time. The only tricky one is ONE which is usually not presented.

My understanding is that %UNIT% will use the unit of the QuantityType anyway so the "of type Number" could be

"of type Number, Number:<dimension> use %.0f unit. If Number use %.0f."

@dilyanpalauzov
Copy link
Contributor Author

The unit should always be guessable.

I meant for items of type just Number or Number:Dimensionless.

@rkoshak
Copy link

rkoshak commented Jan 29, 2024

Right, if it's a Number it will never have a unit. If it's a Number:Dimensionless it will always have a unit. The ONE unit on Number:Dimensionless is usually not shown but it's still there.

You can always know the unit or if there is no unit.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

For unmanaged items, I believe we can simply set the default pattern to items at this place, that is when no pattern is defined inside the label:
https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.model.item/src/org/openhab/core/model/item/internal/GenericItemProvider.java#L259

I will prepare a PR and test it.

For items managed by Main UI, maybe the solution would be to have a pattern proposed by default in the page used to create a new item ?

@mherwege
Copy link
Contributor

mherwege commented Apr 7, 2024

For items managed by Main UI, maybe the solution would be to have a pattern proposed by default in the page used to create a new item ?

See here: openhab/openhab-webui#2485
This would solve it when creating items from a channel in the UI. I could extend that with defaults when creating any item.

@dilyanpalauzov
Copy link
Contributor Author

Do you mean with “managed item” an item, created over the web interface, because the web interface enforces saving state presentation? Or it does not enforce saving state presentation and the rationale is different?

lolodomo added a commit to lolodomo/openhab-core that referenced this issue Apr 7, 2024
…ed items

Related to openhab#4071 and openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

  • of type DateTime to use implicit [%s]

This leads to a very long value, look at my screenshot in the proposed PR. Maybe we should reduce the default to show year, month, day, hour, minute and second ? Precision after the seconds is generally not useful while it takes a lot of place.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

Do you mean with “managed item” an item, created over the web interface

Yes, we call "managed" what is managed by UI, so created/modified/removed from Main UI.
We call "unmanaged" what comes from config files, /items file in the current case.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

For items of type number with a dimension, I propose %.0f %unit% as default presentation pattern, the unit defined for this item will be used or if not defined the default unit for this dimension.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

because the web interface enforces saving state presentation?

Not today but my suggestion would be to add this field in the creation page for String/Number/DateTime items and to set it to the default value we are now defining. This field will remain optional and a user could decide to remove the default pattern or to enter a different pattern if he prefers for any reason.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 7, 2024

For items of type number with a dimension, I propose %.0f %unit% as default presentation pattern, the unit defined for this item will be used or if not defined the default unit for this dimension.

Done, it works.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 8, 2024

The latter logic should be applied also to Group:Number:<dimension>, Group:Number:<dimension>:<function>, Group:Number and Group:Number:<function>.

I see what is Group:Number:<function> but not what is Group:Number:.please provide an example.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 8, 2024

  • of type DateTime to use implicit [%s], spelling NULL when the value is NULL
  • of type String, as above

Regarding NULL/UNDEF, this is a totally separate request for change, "-" is currently displayed if I am not wrong. I believe it was a deliberate choice to not show to user a too much technical value. I do not remember if this is done globally in OH or only at sitemap UI level. I will search.
@openhab/core-maintainers : will you agree with such a change?

@dilyanpalauzov
Copy link
Contributor Author

The latter logic should be applied also to Group:Number:<dimension>, Group:Number:<dimension>:<function>, Group:Number and Group:Number:<function>.

I see what is Group:Number:<function> but not what is Group:Number:.please provide an example.

I think if Number exists (without explicit dimensiom), then Group:Number must also exist. Is the latter invalid syntax? I thought if Number provides some implicit state presentation, then Group:Number should provide the same implicit state presentation.

@dilyanpalauzov
Copy link
Contributor Author

Regarding NULL/UNDEF, this is a totally separate request for change, "-" is currently displayed if I am not wrong. I believe it was a deliberate choice to not show to user a too much technical value.

Writing transforms one has to handle currently three different states: -, NULL and UNDEF: openhab/openhab-addons#13777.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 8, 2024

I think if Number exists (without explicit dimensiom), then Group:Number must also exist. Is the latter invalid syntax? I thought if Number provides some implicit state presentation, then Group:Number should provide the same implicit state presentation.

What I mean is that a group has generally no state (it is just a container) except if you apply an aggregation function on it. There is a default function, EQUALITY., so that is probably the reason why you mentioned the two cases, with and without a function.

https://www.openhab.org/docs/configuration/items.html#derive-group-state-from-member-items

lolodomo added a commit to lolodomo/openhab-core that referenced this issue Apr 10, 2024
Closes openhab#4071
Closes openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor

lolodomo commented Apr 10, 2024

My proposal in the PR is now for all items, managed and unmanaged.

lolodomo added a commit to lolodomo/openhab-core that referenced this issue Apr 11, 2024
Default pattern for string item: %s
Default pattern for datetime item: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item: %.àf
Default pattern for number with dimension item: %.àf %unit%

Closes openhab#4071
Closes openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Apr 11, 2024
Default pattern for string item: %s
Default pattern for datetime item: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item: %.0f
Default pattern for number with dimension item: %.0f %unit%

Closes openhab#4071
Closes openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
lolodomo added a commit to lolodomo/openhab-core that referenced this issue Apr 11, 2024
A default state pattern was previously provided by ChannelStateDescriptionProvider only for String and Number items linked to a channel.
It is now the class DefaultStateDescriptionFragmentProvider which is responsible for providing the default state pattern for items, whether the item is linked to a channel or not.
This new class is the lowest ranked StateDescriptionFragmentProvider so that all other providers have priority in setting the state pattern.

Default pattern for string item: %s
Default pattern for datetime item or group with datetime state: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item or group with number state: %.0f
Default pattern for number+dimension item or group with number+dimension state: %.0f %unit%

Closes openhab#4071
Closes openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor

My PR is now finished and ready for review for the default state pattern.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 11, 2024

  • of type DateTime to use implicit [%s], spelling NULL when the value is NULL
  • of type String, as above

Regarding NULL/UNDEF, this is a totally separate request for change, "-" is currently displayed if I am not wrong. I believe it was a deliberate choice to not show to user a too much technical value. I do not remember if this is done globally in OH or only at sitemap UI level. I will search. @openhab/core-maintainers : will you agree with such a change?

Regarding this second request for change, I believe this conversion of NULL and UNDEF states into "-" is done here and also applies to the value passed to the transformation (if one is provided).
https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java#L398
I am still not sure we really want to change that. Note that it looks like a breaking change for users.

@dilyanpalauzov
Copy link
Contributor Author

I think if Number exists (without explicit dimensiom), then Group:Number must also exist. Is the latter invalid syntax? I thought if Number provides some implicit state presentation, then Group:Number should provide the same implicit state presentation.

What I mean is that a group has generally no state (it is just a container) except if you apply an aggregation function on it. There is a default function, EQUALITY., so that is probably the reason why you mentioned the two cases, with and without a function.

https://www.openhab.org/docs/configuration/items.html#derive-group-state-from-member-items

Honestly, I do not remember what I had in mind when I opened the ticket and I have now no OH environment for tests. As EQUITY is explicit, apparently there is no way to create a Group:Number without a function.

lolodomo added a commit to lolodomo/openhab-core that referenced this issue May 1, 2024
A default state pattern was previously provided by ChannelStateDescriptionProvider only for String and Number items linked to a channel.
It is now the class DefaultStateDescriptionFragmentProvider which is responsible for providing the default state pattern for items, whether the item is linked to a channel or not.
This new class is the lowest ranked StateDescriptionFragmentProvider so that all other providers have priority in setting the state pattern.

Default pattern for string item: %s
Default pattern for datetime item or group with datetime state: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item or group with number state: %.0f
Default pattern for number+dimension item or group with number+dimension state: %.0f %unit%

Closes openhab#4071
Closes openhab#3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@lolodomo
Copy link
Contributor

lolodomo commented May 1, 2024

  • of type DateTime to use implicit [%s], spelling NULL when the value is NULL
  • of type String, as above

Regarding NULL/UNDEF, this is a totally separate request for change, "-" is currently displayed if I am not wrong. I believe it was a deliberate choice to not show to user a too much technical value. I do not remember if this is done globally in OH or only at sitemap UI level. I will search. @openhab/core-maintainers : will you agree with such a change?

Regarding this second request for change, I believe this conversion of NULL and UNDEF states into "-" is done here and also applies to the value passed to the transformation (if one is provided). https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/items/ItemUIRegistryImpl.java#L398 I am still not sure we really want to change that. Note that it looks like a breaking change for users.

Finally, it could make sense to change that, for consistency with what is doing Main UI.

@dilyanpalauzov
Copy link
Contributor Author

Finally, it could make sense to change that, for consistency with what is doing Main UI.

I am lost in the discussion. Can you please describe what makes sense to change, what is the current state, and the possible final, changed state.

@lolodomo
Copy link
Contributor

lolodomo commented May 2, 2024

I was talking about your proposal to not convert NULL/UNDEF into -.

J-N-K pushed a commit that referenced this issue May 2, 2024
…4175)

* Set a default presentation pattern for String/Number/Datetime items

A default state pattern was previously provided by ChannelStateDescriptionProvider only for String and Number items linked to a channel.
It is now the class DefaultStateDescriptionFragmentProvider which is responsible for providing the default state pattern for items, whether the item is linked to a channel or not.
This new class is the lowest ranked StateDescriptionFragmentProvider so that all other providers have priority in setting the state pattern.

Default pattern for string item: %s
Default pattern for datetime item or group with datetime state: %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
Default pattern for number item or group with number state: %.0f
Default pattern for number+dimension item or group with number+dimension state: %.0f %unit%

Closes #4071
Closes #3835

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
@dilyanpalauzov
Copy link
Contributor Author

I was talking about your proposal to not convert NULL/UNDEF into -.

Will this happen?

@lolodomo
Copy link
Contributor

lolodomo commented May 3, 2024

First, I hope you are happy that your main proposal was implemented and accepted ?

I was talking about your proposal to not convert NULL/UNDEF into -.

Will this happen?

Please create another dedicated request for change to discuss of it. You could explain why you think it is better to display a raw value "UNDEF" / "NULL" rather than "-" for UNDEF and NULL states. I will then add pros and cons. I hope we can engage a discussion with others. The change itself is very easy to implement and I could do it.

@dilyanpalauzov
Copy link
Contributor Author

Yes, I am happy that this is implemented. About NULL, UNDEF and - I have filled openhab/openhab-addons#13777.

@lolodomo
Copy link
Contributor

lolodomo commented May 4, 2024

About NULL, UNDEF and - I have filled openhab/openhab-addons#13777.

This is not exactly the same request. In your other issue, you are requesting a consistent behaviour regarding transformations in Main UI and sitemap UIs. Your other request makes sense, read my analysis in the other issue.

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 a pull request may close this issue.

4 participants