2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hue.internal.handler;
15 import java.util.Locale;
17 import java.util.concurrent.ConcurrentHashMap;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.thing.Channel;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider;
24 import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
25 import org.openhab.core.thing.type.DynamicStateDescriptionProvider;
26 import org.openhab.core.types.StateDescription;
27 import org.osgi.service.component.annotations.Activate;
28 import org.osgi.service.component.annotations.Component;
29 import org.osgi.service.component.annotations.Reference;
32 * Dynamic provider of state options for {@link HueBridgeHandler} while leaving other state description fields as
35 * @author Hengrui Jiang - Initial contribution
37 @Component(service = { DynamicStateDescriptionProvider.class, HueStateDescriptionOptionProvider.class })
39 public class HueStateDescriptionOptionProvider extends BaseDynamicStateDescriptionProvider {
41 private final Map<ChannelUID, StateDescription> descriptions = new ConcurrentHashMap<>();
44 public HueStateDescriptionOptionProvider(
45 final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
46 this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
49 public void setDescription(ChannelUID channelUID, StateDescription description) {
50 descriptions.put(channelUID, description);
54 public @Nullable StateDescription getStateDescription(Channel channel,
55 @Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
56 StateDescription stateDescription = descriptions.get(channel.getUID());
57 return stateDescription != null ? stateDescription
58 : super.getStateDescription(channel, originalStateDescription, locale);