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.yeelight.internal;
15 import static org.openhab.binding.yeelight.internal.YeelightBindingConstants.*;
17 import java.util.HashSet;
20 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingHandler;
21 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingWithAmbientHandler;
22 import org.openhab.binding.yeelight.internal.handler.YeelightCeilingWithNightHandler;
23 import org.openhab.binding.yeelight.internal.handler.YeelightColorHandler;
24 import org.openhab.binding.yeelight.internal.handler.YeelightStripeHandler;
25 import org.openhab.binding.yeelight.internal.handler.YeelightWhiteHandler;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Component;
34 * The {@link YeelightHandlerFactory} is responsible for returning supported things and handlers for the devices.
36 * @author Coaster Li - Initial contribution
37 * @author Nikita Pogudalov - Added YeelightCeilingWithNightHandler for Ceiling 1
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.yeelight")
40 public class YeelightHandlerFactory extends BaseThingHandlerFactory {
41 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = new HashSet<>();
44 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_CEILING);
45 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_CEILING1);
46 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_CEILING3);
47 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_CEILING4);
48 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_DOLPHIN);
49 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_CTBULB);
50 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_WONDER);
51 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_STRIPE);
52 SUPPORTED_THING_TYPES_UIDS.add(THING_TYPE_DESKLAMP);
56 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
61 protected ThingHandler createHandler(Thing thing) {
62 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
64 if (thingTypeUID.equals(THING_TYPE_DOLPHIN) || thingTypeUID.equals(THING_TYPE_CTBULB)) {
65 return new YeelightWhiteHandler(thing);
66 } else if (thingTypeUID.equals(THING_TYPE_WONDER)) {
67 return new YeelightColorHandler(thing);
68 } else if (thingTypeUID.equals(THING_TYPE_STRIPE)) {
69 return new YeelightStripeHandler(thing);
70 } else if (thingTypeUID.equals(THING_TYPE_CEILING) || thingTypeUID.equals(THING_TYPE_DESKLAMP)) {
71 return new YeelightCeilingHandler(thing);
72 } else if (thingTypeUID.equals(THING_TYPE_CEILING1) || thingTypeUID.equals(THING_TYPE_CEILING3)) {
73 return new YeelightCeilingWithNightHandler(thing);
74 } else if (thingTypeUID.equals(THING_TYPE_CEILING4)) {
75 return new YeelightCeilingWithAmbientHandler(thing);