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.amazonechocontrol.internal.smarthome;
15 import static org.openhab.binding.amazonechocontrol.internal.AmazonEchoControlBindingConstants.BINDING_ID;
17 import java.util.Locale;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.amazonechocontrol.internal.handler.SmartHomeDeviceHandler;
22 import org.openhab.core.thing.Channel;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingRegistry;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.thing.type.ChannelTypeUID;
27 import org.openhab.core.thing.type.DynamicStateDescriptionProvider;
28 import org.openhab.core.types.StateDescription;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
35 * Dynamic channel state description provider
36 * Overrides the state description for the colors of the smart bulbs
38 * @author Lukas Knoeller - Initial contribution
42 @Component(service = { DynamicStateDescriptionProvider.class, DynamicStateDescriptionSmartHome.class })
44 public class DynamicStateDescriptionSmartHome implements DynamicStateDescriptionProvider {
45 private final ThingRegistry thingRegistry;
48 public DynamicStateDescriptionSmartHome(@Reference ThingRegistry thingRegistry) {
49 this.thingRegistry = thingRegistry;
52 public @Nullable SmartHomeDeviceHandler findHandler(Channel channel) {
53 Thing thing = thingRegistry.get(channel.getUID().getThingUID());
57 ThingHandler handler = thing.getHandler();
58 if (handler instanceof SmartHomeDeviceHandler smartHomeHandler) {
59 return smartHomeHandler;
65 public @Nullable StateDescription getStateDescription(Channel channel,
66 @Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
67 ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
68 if (channelTypeUID == null || !BINDING_ID.equals(channelTypeUID.getBindingId())) {
71 if (originalStateDescription == null) {
74 SmartHomeDeviceHandler handler = findHandler(channel);
75 if (handler != null) {
76 return handler.findStateDescription(channel, originalStateDescription, locale);