2 * Copyright (c) 2010-2022 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
14 package org.openhab.binding.shelly.internal.provider;
16 import java.util.Locale;
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;
29 * This class provides the list of valid inputs for the input channel of a source.
31 * @author Markus Michels - Initial contribution
35 public class ShellyStateDescriptionProvider extends BaseDynamicStateDescriptionProvider implements ThingHandlerService {
36 private @Nullable ShellyThingInterface handler;
39 public void setThingHandler(ThingHandler handler) {
40 this.handler = (ShellyThingInterface) handler;
44 public @Nullable ThingHandler getThingHandler() {
45 return (ThingHandler) handler;
48 @SuppressWarnings("null")
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));
56 return super.getStateDescription(channel, original, locale);