]> git.basschouten.com Git - openhab-addons.git/blob
38886862be3b5d0ad7026cea30012336e2332e4a
[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.tradfri.internal;
14
15 import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.tradfri.internal.handler.TradfriAirPurifierHandler;
20 import org.openhab.binding.tradfri.internal.handler.TradfriBlindHandler;
21 import org.openhab.binding.tradfri.internal.handler.TradfriControllerHandler;
22 import org.openhab.binding.tradfri.internal.handler.TradfriGatewayHandler;
23 import org.openhab.binding.tradfri.internal.handler.TradfriLightHandler;
24 import org.openhab.binding.tradfri.internal.handler.TradfriPlugHandler;
25 import org.openhab.binding.tradfri.internal.handler.TradfriSensorHandler;
26 import org.openhab.core.thing.Bridge;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Component;
33
34 /**
35  * The {@link TradfriHandlerFactory} is responsible for creating things and thing handlers.
36  *
37  * @author Kai Kreuzer - Initial contribution
38  * @author Christoph Weitkamp - Added support for remote controller and motion sensor devices (read-only battery level)
39  * @author Manuel Raffel - Added support for blinds
40  */
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.tradfri")
42 @NonNullByDefault
43 public class TradfriHandlerFactory extends BaseThingHandlerFactory {
44
45     @Override
46     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
47         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
48     }
49
50     @Override
51     protected @Nullable ThingHandler createHandler(Thing thing) {
52         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
53
54         if (GATEWAY_TYPE_UID.equals(thingTypeUID)) {
55             return new TradfriGatewayHandler((Bridge) thing);
56         } else if (THING_TYPE_DIMMER.equals(thingTypeUID) || THING_TYPE_REMOTE_CONTROL.equals(thingTypeUID)
57                 || THING_TYPE_OPEN_CLOSE_REMOTE_CONTROL.equals(thingTypeUID)) {
58             return new TradfriControllerHandler(thing);
59         } else if (THING_TYPE_MOTION_SENSOR.equals(thingTypeUID)) {
60             return new TradfriSensorHandler(thing);
61         } else if (THING_TYPE_BLINDS.equals(thingTypeUID)) {
62             return new TradfriBlindHandler(thing);
63         } else if (SUPPORTED_LIGHT_TYPES_UIDS.contains(thingTypeUID)) {
64             return new TradfriLightHandler(thing);
65         } else if (SUPPORTED_PLUG_TYPES_UIDS.contains(thingTypeUID)) {
66             return new TradfriPlugHandler(thing);
67         } else if (THING_TYPE_AIR_PURIFIER.equals(thingTypeUID)) {
68             return new TradfriAirPurifierHandler(thing);
69         }
70         return null;
71     }
72 }