]> git.basschouten.com Git - openhab-addons.git/blob
d16eaf7191808fa03474fd690f75e81aac7bb0f4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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
14 package org.openhab.binding.shelly.internal.provider;
15
16 import java.util.Locale;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.shelly.internal.handler.ShellyThingInterface;
21 import org.openhab.core.thing.Channel;
22 import org.openhab.core.thing.binding.BaseDynamicStateDescriptionProvider;
23 import org.openhab.core.thing.binding.ThingHandler;
24 import org.openhab.core.thing.binding.ThingHandlerService;
25 import org.openhab.core.thing.type.ChannelTypeUID;
26 import org.openhab.core.types.StateDescription;
27
28 /**
29  * This class provides the list of valid inputs for the input channel of a source.
30  *
31  * @author Markus Michels - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class ShellyStateDescriptionProvider extends BaseDynamicStateDescriptionProvider implements ThingHandlerService {
36     private @Nullable ShellyThingInterface handler;
37
38     @Override
39     public void setThingHandler(ThingHandler handler) {
40         this.handler = (ShellyThingInterface) handler;
41     }
42
43     @Override
44     public @Nullable ThingHandler getThingHandler() {
45         return (ThingHandler) handler;
46     }
47
48     @SuppressWarnings("null")
49     @Override
50     public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original,
51             @Nullable Locale locale) {
52         ChannelTypeUID uid = channel.getChannelTypeUID();
53         if (uid != null && handler != null) {
54             setStateOptions(channel.getUID(), handler.getStateOptions(uid));
55         }
56         return super.getStateDescription(channel, original, locale);
57     }
58 }