]> git.basschouten.com Git - openhab-addons.git/blob
85995f3d87c3dece55b70b909c0b2b760c7a900a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.yeelight.internal;
14
15 import static org.openhab.binding.yeelight.internal.YeelightBindingConstants.*;
16
17 import java.util.HashSet;
18 import java.util.Set;
19
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;
27
28 /**
29  * The {@link YeelightHandlerFactory} is responsible for returning supported things and handlers for the devices.
30  *
31  * @author Coaster Li - Initial contribution
32  * @author Nikita Pogudalov - Added YeelightCeilingWithNightHandler for Ceiling 1
33  */
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<>();
37
38     static {
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);
48     }
49
50     @Override
51     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
52         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
53     }
54
55     @Override
56     protected ThingHandler createHandler(Thing thing) {
57         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
58
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);
72         } else {
73             return null;
74         }
75     }
76 }