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