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)) {
61 SmartHomeDeviceHandler smartHomeHandler = (SmartHomeDeviceHandler) handler;
62 return smartHomeHandler;
66 public @Nullable StateDescription getStateDescription(Channel channel,
67 @Nullable StateDescription originalStateDescription, @Nullable Locale locale) {
68 ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
69 if (channelTypeUID == null || !BINDING_ID.equals(channelTypeUID.getBindingId())) {
72 if (originalStateDescription == null) {
75 SmartHomeDeviceHandler handler = findHandler(channel);
76 if (handler != null) {
77 return handler.findStateDescription(channel, originalStateDescription, locale);