Changing the "step" value of a channel type state

Hello,

I have defined the following channel type:

	<channel-type id="setpointTemperature">
		<item-type>Number:Temperature</item-type>
		<label>@text/channel-type.airzone.zone.setpointTemperature.label</label>
		<category>Temperature</category>
		<tags>
			<tag>Setpoint</tag>
			<tag>Temperature</tag>
		</tags>
		<state min="15" max="30" step="0.5" pattern="%.1f °C" readOnly="false"/>
	</channel-type>

As you can see, the state defines a step at which the setpoint temperature can be changed, which is conveniently taken into account in MainUI.

However, in the case of my binding, the API gives a double value that indicates the acceptable temperature steps. In my case its value is 0.5 but the documentation says the 1 value also exists.

Is there a way to modify the channel type state “step” value to match the value from the API?
I know I could have two different types and use that to dynamically create the setpoint temperature channel, but it feels quite cumbersome, especially if a future release of the device allows for any other step value.

Thanks for your help.

Look at the BaseDynamicStateDescriptionProvider

Thanks, that’s what I could have found by looking at the code from other plugins.

I did, however, directly implement the DynamicStateDescriptionProvider interface as the BaseDynamicStateDescriptionProvider class brought too much complexity for my use case.

As a reference to my future self and others, the idea is basically to override getStateDescription and use a StateDescriptionFragmentBuilder to return the new state.
Just make sure to exit as early as possible from that override as it gets called for any channel known to openHAB, even for things not handled by your binding. And the proper way to say “I did not change anything” is to return null.

For those interested, I implemented it in that commit:

1 Like