I’m questioning myself about the usage of channel state configuration:
- Where is it use ?
- How do we use it ?
- What the purpose of it ?
I’ve created a channel of type Number with a min and max as follow:
<description>Color Temperature. Range 1700 ~ 6500(K)</description>
<state min="1700" max="6500" step="1" pattern="%d K"></state>
Since it’s a Number the default widget just display the value:
If I override the default standalone widget (by the metadata menu) with Knob for instance the default range is 0 to 100.
If I select a value (10 for instance) it will be passed to the “org.openhab.core.thing.binding.ThingHandler.handleCommand(ChannelUID, Command)” method even if that channel as a min of 1700.
Is that normal ?
Should I retrieve the state configuration min/max inside this method to compare it with the value set by the user ? Is that even possible ?
Does the state is only used by item type that have a user action by default ? Like dimmer ?
If I set my item-type to Dimmer instead of Number the default widget looks good but it fail to set the state since It expect a value between 0 and 100.
Is it possible to define a default widget in the code ?
Thank you for your time
My understanding, which could be way off, is that a binding can set some default parameters for the State Description metadata on an Item at Link time. However, if the user comes along and changes that metadata later, whatever the user does takes precedence (as it should)…
I think the min, max, options and such in the State Description metadata are applied when the default widget as chosen by MainUI is used. For example, if I have a Setpoint tagged Item, a Slider widget will be selected by MainUI and it will use the min/max/etc values from the State Description.
However, if the user supplies their own default widget metadata, the State Description values are ignored (unless the user explicitly references them which I’m not entirely certain is even possible actually).
I do not think there is a way for a binding to supply a default widget Item metadata.
My understanding was that since the binding channel is the link to the device the state from the channel-type would have been the limit of the thing.
Is there a way to retrieve the “default state” of the channel-type from code ?
If I create an item with class “Point_Setpoint” linked to my channel of type Number with min and max I get an oh-input-card without any min/max:
however if now I add the semantic property “Color Temperature” I get a oh-slider-card which is configured with min/max.
So maybe there is a bug in the oh-input-card.
Thank you very much that was helpful
Probably more likely that you need to supply both the Point and Properties tag for MainUI to pick an appropriate default widget.