]> git.basschouten.com Git - openhab-addons.git/blob
fd3f0114e03c70b6a09631514a0eba59236995a4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.elroconnects.internal;
14
15 import java.util.Locale;
16 import java.util.Map;
17 import java.util.concurrent.ConcurrentHashMap;
18
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.type.DynamicStateDescriptionProvider;
24 import org.openhab.core.types.StateDescription;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Deactivate;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 /**
31  *
32  * @author Mark Herwege - Initial contribution
33  */
34 @Component(service = { DynamicStateDescriptionProvider.class, ElroConnectsDynamicStateDescriptionProvider.class })
35 @NonNullByDefault
36 public class ElroConnectsDynamicStateDescriptionProvider implements DynamicStateDescriptionProvider {
37
38     private final Logger logger = LoggerFactory.getLogger(ElroConnectsDynamicStateDescriptionProvider.class);
39
40     private final Map<ChannelUID, @Nullable StateDescription> descriptions = new ConcurrentHashMap<>();
41
42     public void setDescription(ChannelUID channelUID, @Nullable StateDescription description) {
43         logger.debug("Adding command description for channel {}", channelUID);
44         descriptions.put(channelUID, description);
45     }
46
47     public void removeAllDescriptions() {
48         logger.debug("Removing all command descriptions");
49         descriptions.clear();
50     }
51
52     @Override
53     public @Nullable StateDescription getStateDescription(Channel channel,
54             @Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
55         StateDescription description = descriptions.get(channel.getUID());
56         return description;
57     }
58
59     @Deactivate
60     public void deactivate() {
61         descriptions.clear();
62     }
63 }