-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Save stateDescriptionPattern from channel type for UoM Items & Save UoM metadata when adding from model #2485
Conversation
Job #1897: Bundle Size — 10.56MiB (+0.01%).Warning Bundle contains 2 duplicate packages – View duplicate packages Bundle metrics
|
Current Job #1897 |
Baseline Job #1894 |
|
---|---|---|
Initial JS | 1.86MiB (~+0.01% ) |
1.86MiB |
Initial CSS | 607.87KiB |
607.87KiB |
Cache Invalidation | 18.3% |
17.8% |
Chunks | 223 |
223 |
Assets | 246 |
246 |
Modules | 2861 |
2861 |
Duplicate Modules | 141 |
141 |
Duplicate Code | 1.73% |
1.73% |
Packages | 95 |
95 |
Duplicate Packages | 2 |
2 |
Bundle size by type 1 change
1 regression
Current Job #1897 |
Baseline Job #1894 |
|
---|---|---|
JS | 8.75MiB (+0.01% ) |
8.75MiB |
CSS | 890.07KiB |
890.07KiB |
Fonts | 526.1KiB |
526.1KiB |
Media | 295.6KiB |
295.6KiB |
IMG | 140.74KiB |
140.74KiB |
HTML | 1.24KiB |
1.24KiB |
Other | 871B |
871B |
View job #1897 report View mherwege:stateDescription branch activity View project dashboard
From linked PR: openhab/openhab-addons#16531
I think this whole concept is unfortunately messy, but difficult to change without breaking things. This PR proposes to show the channel type state description pattern when originally creating an item linked to a channel of a thing. That gives users the possibility to set something else if that makes sense. It avoids changing item display state update behaviour. |
I'm sure you've already thought about this but one little wrinkle to keep in the back of your mind as you work this is sometimes the type of the destination Item may be dramatically different from the type the Channel (and therefore the state description pattern pushed by binding) may not even make sense. For example, if you have a timestamp profile on the link between a Number:Dimensionless Channel and a DateTime Item, I don't think there's a problem here, just wanted to mention it. |
@rkoshak Thank you for the insight. I didn’t consider that so far. But with the change as implemented so far, it shouldn’t change the current behavior. But I honestly don’t know how the system currently copes with it. Does it ignore channel type state descriptions when a profile changing to a different type is used? |
Awhile back it was actually causing a bunch of problems because some bindings would push state description "options" which were silently applied to the Item but because the Item type changed due to a profile it messed up everything in the state description. This was a couple years ago now I think. I was under the impression that when that problem was sorted it also addressed the pattern. But I don't know how to test it. My searching has so far failed to show the original issue or PR. I don't think it forces the metadata to be created though. I think it's only kept in memory somehow. |
Probably this: openhab/openhab-core#2283 And here is another issue with this when using profiles: openhab/openhab-core#4050 |
Those both look like the same overall issue but neither is the one I'm thinking about. But I could be mistaken about my memory that it got fixed if these are open. And it could have been a forum thread I'm remembering. There's so much to keep track of. |
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
ad7cf03
to
927c7d8
Compare
@mherwege I was wondering how to make progress on this topic. And how to resolve the prior as yet unresolved issues. I suggest that the code must comply with the "functional specification" for state descriptions as written in the state description developer document This functional specification is either a) fully correct, b) fully wrong, or c) missing something. If the functional specification is fully correct, then this PR MUST follow that verbatim. Otherwise if the functional specification is wrong or missing something then we should first edit and agree upon the functional specification BEFORE we try to review the code in this PR. => WDYT? |
@andrewfg This PR does not have the ambition to resolve all issues with state descriptions when applying profiles. It merely tries to capture the state description pattern from the channel type and apply it when creating a new item with dimension number and a type and make sure it is applied to the item. It avoids mismatches in the UI and unpredictability because of mismatches in channel type state description patterns. The UI naively supposed so far a %0.f %unit% pattern when nothing was set in the UI. From my perspective, this PR still complies with the functional specification. All other parameters in the state description should not be touched by this PR. Where do you think I go wrong with this reasoning? |
^ |
@andrewfg I still think the doc and this PR are mutually consistent. I spend some extra time testing. This PR will only set the state description pattern (not the full state description) for a Number Dimension item when creating an item from a thing channel. It copies the state description pattern from the channel type and saves that, or saves a new value set by the user. Channel type for a channel on a binding (I used nikohomecontrol):
I create an item linked to a channel on the binding and explicitly set a state description pattern of
You clearly see the effect of merging the state description. So I see no inconsistency between documentation and what I try to do here. The only thing you could argue about is that no warning is given on the effect of merging state descriptions (which is already the case without this PR) on the resulting state description in the documentation. If you feel differently, please let me know. I will be happy to change this PR. But at this time, I don't see how it would invalidate the documentation and current contract in the slightest way. |
@mherwege many thanks for the explanation above. Based on that, I think the following..
Further questions..
|
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
My understanding is it is part of the state description and will get merged with the rules I explained. There is no attempt in this PR to do anything with the state description beyond the state description pattern for Number Dimension items. |
After reading though the discussion in this PR and the docs, I am also fine with the current state of this PR and will review this PR once I’m back in action. I have a few comments on the above:
Can you please improve the docs to mention that?
Seems like the UI does not always take these into account, for example does oh-slider not get its min and max values from the state description of the Item: https://github.com/openhab/openhab-webui/blob/4a0054a1f020cbec8a1590d550e60542826d8504/bundles/org.openhab.ui/web/src/components/widgets/system/oh-slider.vue |
A small fix in this documentation would be necessary.
This is also applicable to DateTime items. |
@mherwege : can you check you are aligned with my PR openhab/openhab-core#4175 for the default pattern. As a reminder, for a number with dimension item, ChannelStateDescriptionProvider will set "%.0f" as default pattern if none is provided by the channel. The current order when merging state descriptions from the different providers, from the highest priority to the lowest priority:
With my change, it will become:
|
I am aligned with that and I believe both complement each other well. Note that this PR at its current state only does impact the state description pattern for items with dimension. With the changes in openhab/openhab-core#4175 a next step would be to expose the state description pattern for all items and set it in he same way as for items with dimension. This would solve the issue of potential conflicting channel state description patterns when linking items to two channels with different state description patterns (at least in the UI when creating items from a channel). It effectively promotes one of the state description patterns to the highest priority level by setting it explicitly in metadata. |
Normally with my PR, you don't need to set a default state pattern if not provided by channel. |
This PR only sets it when creating an item from a channel or thing (model), so not for new unlinked items. |
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, thanks!
Just one thing: IMO we should disable the state description field for existing Items, because changing the state description is a potentially dangerous operation. If you change the pattern, the rest of the metadata is overwritten, so you may loose your defined pattern etc. by mistake.
I will soon push a commit to disable this field for existing Items and show a message:
Pattern can only be changed from the state description metadata page after Item creation!
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@mherwege Please let me know if you agree! |
Wouldn’t it be better to merge with the rest of the state description if one already exists on save to avoid this? |
This would allow to change the state description pattern easily when changing the unit, but in case you have a min/max you would have to go the state description metadata page anyway to change them. And „hiding“ min/max when allowing to change the state description pattern could cause confusion.
It is not hidden, only disabled with a hint to go to the state description metadata page. IMO it is safer to disable the state description pattern field in the item-form, because you then force the user to see and think about the whole state description when he wants to change the pattern afterwards. |
OK to disable. while I started this for the state description pattern in the context of UOM, I still think there is further room for improvement. It is not only the state description pattern that can contain conflicting information when linked to multiple channels, but the whole of the state description. For the pattern, it is solved here in the UI by copying he pattern from the channel when creating the item, thereby giving a higher priority to the first one (with the ability to change). Something similar would probably be good to do for the rest of the state description. But I considered that beyond he scope of his PR. |
Agreed and your proposal for another PR sounds nice 👍 |
@mherwege many thanks for the contribution! |
When creating a new Number with Dimension item from a channel link, the stateDescriptionPattern does not propose the state description pattern from the channel type as the default.
This PR introduces this.
It only saves this state description pattern from the channel type to metadata of the item if it is not the default state description pattern for a Number type.
Subsequent edits of the item will present a disabled state description pattern input.
If no state description field is set, a blank field will be presented.
Reasons are:
Saving only the pattern would override the rest of the stateDescription.
The only solution would be for the user the set it on the item and override the channel stateDescriptions.
See openhab/openhab-addons#16531 (comment).
This PR also now saves the unit (and state description pattern) when creating equipment or point from a thing.
See discussion https://community.openhab.org/t/units-are-not-propagated-when-creating-items/154748.
So far, changes were only saved when editing or creating items directly or from thing channels, not when creating from things in the model.