]> git.basschouten.com Git - openhab-addons.git/blob
997f1f68e5853f2c49b0234380d231f5633c6c46
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.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;
32
33 /**
34  * The {@link YeelightHandlerFactory} is responsible for returning supported things and handlers for the devices.
35  *
36  * @author Coaster Li - Initial contribution
37  * @author Nikita Pogudalov - Added YeelightCeilingWithNightHandler for Ceiling 1
38  */
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<>();
42
43     static {
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);
53     }
54
55     @Override
56     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
58     }
59
60     @Override
61     protected ThingHandler createHandler(Thing thing) {
62         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
63
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);
76         } else {
77             return null;
78         }
79     }
80 }