I want to upgrade my dynamic state description to include min/max/step. I am using the setStateOptions() setStatePattern()
provided in the BaseStateDescriptionProvider
. I created my own:
public class HoneywellStateDescriptionProvider extends BaseDynamicStateDescriptionProvider {
protected final Map<ChannelUID, List<BigDecimal>> channelMinMaxStepMap = new ConcurrentHashMap<>();
@Activate
public HoneywellStateDescriptionProvider(final @Reference EventPublisher eventPublisher, //
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry, //
final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
this.eventPublisher = eventPublisher;
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
}
public void setMinMaxStep(ChannelUID channelUID, List<BigDecimal> newMinMaxStep) {
List<BigDecimal> oldMinMaxStep = channelMinMaxStepMap.get(channelUID);
if (!oldMinMaxStep.equals(newMinMaxStep)) {
channelMinMaxStepMap.put(channelUID, newMinMaxStep);
}
}
@SuppressWarnings("unused")
@Override
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original,
@Nullable Locale locale) {
// can be overridden by subclasses
ChannelUID channelUID = channel.getUID();
List<BigDecimal> bigDecimals = channelMinMaxStepMap.get(channelUID);
if (bigDecimals == null) {
return super.getStateDescription(channel, original, locale);
}
StateDescriptionFragmentBuilder builder = (original == null) ? StateDescriptionFragmentBuilder.create()
: StateDescriptionFragmentBuilder.create(original);
builder.withMinimum(bigDecimals.get(0)).withMaximum(bigDecimals.get(1)).withStep(bigDecimals.get(2));
return super.getStateDescription(channel, builder.build().toStateDescription(), locale);
}
}
But the original has:
postEvent(ThingEventFactory.createChannelDescriptionPatternChangedEvent(channelUID,
itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(),
pattern, oldPattern));
Which I have no idea what it is doing or why it is needed (never a good sign). My question is do I need to learn about it in order to get my Min/Max/Step to properly work? Since it is a black box to me I don’t know what gotchas will occur if I don’t figure it out.