2 * Copyright (c) 2010-2023 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.tr064.internal;
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.ThingUID;
24 import org.openhab.core.thing.type.DynamicStateDescriptionProvider;
25 import org.openhab.core.types.StateDescription;
26 import org.osgi.service.component.annotations.Component;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Dynamic channel state description provider.
32 * Overrides the state description for the controls, which receive its configuration in the runtime.
34 * @author Jan N. Klug - Initial contribution
37 @Component(service = { DynamicStateDescriptionProvider.class, Tr064DynamicStateDescriptionProvider.class })
38 public class Tr064DynamicStateDescriptionProvider implements DynamicStateDescriptionProvider {
39 private final Logger logger = LoggerFactory.getLogger(Tr064DynamicStateDescriptionProvider.class);
40 private final Map<ChannelUID, StateDescription> descriptions = new ConcurrentHashMap<>();
43 * Set a state description for a channel. This description will be used when preparing the channel state by
44 * the framework for presentation. A previous description, if existed, will be replaced.
46 * @param channelUID channel UID
47 * @param description state description for the channel
49 public void setDescription(ChannelUID channelUID, StateDescription description) {
50 logger.trace("adding state description for channel {}", channelUID);
51 descriptions.put(channelUID, description);
55 * remove all descriptions for a given thing
57 * @param thingUID the thing's UID
59 public void removeDescriptionsForThing(ThingUID thingUID) {
60 logger.trace("removing state description for thing {}", thingUID);
61 descriptions.entrySet().removeIf(entry -> entry.getKey().getThingUID().equals(thingUID));
65 public @Nullable StateDescription getStateDescription(Channel channel,
66 @Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
67 if (descriptions.containsKey(channel.getUID())) {
68 return descriptions.get(channel.getUID());