Package org.openhab.core.thing.binding
Class BaseDynamicStateDescriptionProvider
java.lang.Object
org.openhab.core.thing.binding.AbstractDynamicDescriptionProvider
org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider
- All Implemented Interfaces:
DynamicStateDescriptionProvider
@NonNullByDefault
public abstract class BaseDynamicStateDescriptionProvider
extends AbstractDynamicDescriptionProvider
implements DynamicStateDescriptionProvider
The
BaseDynamicStateDescriptionProvider
provides a base implementation for the
DynamicStateDescriptionProvider
.
It provides localized patterns and dynamic StateOption
s while leaving other StateDescription
fields
as original. Therefore the inheriting class has to request a reference for the
ChannelTypeI18nLocalizationService
on its own.
- Author:
- Christoph Weitkamp - Initial contribution, Christoph Weitkamp - Added ChannelStateDescriptionChangedEvent
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<ChannelUID,
List<StateOption>> protected final Map<ChannelUID,
String> Fields inherited from class org.openhab.core.thing.binding.AbstractDynamicDescriptionProvider
bundleContext, channelTypeI18nLocalizationService, eventPublisher, itemChannelLinkRegistry
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
@Nullable StateDescription
getStateDescription
(Channel channel, @Nullable StateDescription original, @Nullable Locale locale) For a givenChannel
, return aStateDescription
that should be used for the channel, instead of the one defined statically in theChannelType
.protected List<StateOption>
localizedStateOptions
(List<StateOption> options, Channel channel, @Nullable Locale locale) Localizes aList
ofStateOption
s that should be used for the channel.protected @Nullable String
localizeStatePattern
(String pattern, Channel channel, @Nullable Locale locale) Localizes a pattern that should be used for the channel.void
setStateOptions
(ChannelUID channelUID, List<StateOption> options) For a givenChannelUID
, set aList
ofStateOption
s that should be used for the channel, instead of the one defined statically in theChannelType
.void
setStatePattern
(ChannelUID channelUID, String pattern) For a givenChannelUID
, set a pattern that should be used for the channel, instead of the one defined statically in theChannelType
.Methods inherited from class org.openhab.core.thing.binding.AbstractDynamicDescriptionProvider
activate, postEvent
-
Field Details
-
channelPatternMap
-
channelOptionsMap
-
-
Constructor Details
-
BaseDynamicStateDescriptionProvider
public BaseDynamicStateDescriptionProvider()
-
-
Method Details
-
setStatePattern
For a givenChannelUID
, set a pattern that should be used for the channel, instead of the one defined statically in theChannelType
.- Parameters:
channelUID
- theChannelUID
of the channelpattern
- a pattern
-
setStateOptions
For a givenChannelUID
, set aList
ofStateOption
s that should be used for the channel, instead of the one defined statically in theChannelType
.- Parameters:
channelUID
- theChannelUID
of the channeloptions
- aList
ofStateOption
s
-
getStateDescription
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original, @Nullable Locale locale) Description copied from interface:DynamicStateDescriptionProvider
For a givenChannel
, return aStateDescription
that should be used for the channel, instead of the one defined statically in theChannelType
. For a particular channel, there should be only one provider of the dynamic state description. When more than one description is provided for the same channel (by different providers), only one will be used, from the provider that registered first. If the given channel will not be managed by the provider null should be returned. You never must return the original state description in such case.- Specified by:
getStateDescription
in interfaceDynamicStateDescriptionProvider
- Parameters:
channel
- channeloriginal
- original state description retrieved from the channel type this is the description to be replaced by the provided onelocale
- locale (can be null)- Returns:
- state description or null if none provided
-
localizeStatePattern
protected @Nullable String localizeStatePattern(String pattern, Channel channel, @Nullable Locale locale) Localizes a pattern that should be used for the channel.- Parameters:
pattern
- a patternchannel
- the channellocale
- a locale- Returns:
- the localized pattern
-
localizedStateOptions
protected List<StateOption> localizedStateOptions(List<StateOption> options, Channel channel, @Nullable Locale locale) Localizes aList
ofStateOption
s that should be used for the channel.- Parameters:
options
- aList
ofStateOption
schannel
- the channellocale
- a locale- Returns:
- the localized
List
ofStateOption
s
-
deactivate
public void deactivate()- Overrides:
deactivate
in classAbstractDynamicDescriptionProvider
-