]> git.basschouten.com Git - openhab-addons.git/blob
257f19c1e23bb301ce653499670aedae0ffc4c2e
[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.velbus.internal;
14
15 import static org.openhab.binding.velbus.internal.VelbusBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.velbus.internal.handler.VelbusBlindsHandler;
20 import org.openhab.binding.velbus.internal.handler.VelbusBridgeHandler;
21 import org.openhab.binding.velbus.internal.handler.VelbusDimmerHandler;
22 import org.openhab.binding.velbus.internal.handler.VelbusNetworkBridgeHandler;
23 import org.openhab.binding.velbus.internal.handler.VelbusRelayHandler;
24 import org.openhab.binding.velbus.internal.handler.VelbusSensorHandler;
25 import org.openhab.binding.velbus.internal.handler.VelbusSensorWithAlarmClockHandler;
26 import org.openhab.binding.velbus.internal.handler.VelbusSerialBridgeHandler;
27 import org.openhab.binding.velbus.internal.handler.VelbusVMB1TSHandler;
28 import org.openhab.binding.velbus.internal.handler.VelbusVMB4ANHandler;
29 import org.openhab.binding.velbus.internal.handler.VelbusVMB7INHandler;
30 import org.openhab.binding.velbus.internal.handler.VelbusVMBELHandler;
31 import org.openhab.binding.velbus.internal.handler.VelbusVMBELOHandler;
32 import org.openhab.binding.velbus.internal.handler.VelbusVMBGPHandler;
33 import org.openhab.binding.velbus.internal.handler.VelbusVMBGPOHandler;
34 import org.openhab.binding.velbus.internal.handler.VelbusVMBMeteoHandler;
35 import org.openhab.binding.velbus.internal.handler.VelbusVMBPIROHandler;
36 import org.openhab.core.io.transport.serial.SerialPortManager;
37 import org.openhab.core.thing.Bridge;
38 import org.openhab.core.thing.Thing;
39 import org.openhab.core.thing.ThingTypeUID;
40 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
41 import org.openhab.core.thing.binding.ThingHandler;
42 import org.openhab.core.thing.binding.ThingHandlerFactory;
43 import org.osgi.service.component.annotations.Activate;
44 import org.osgi.service.component.annotations.Component;
45 import org.osgi.service.component.annotations.Reference;
46
47 /**
48  * The {@link VelbusHandlerFactory} is responsible for creating things and thing
49  * handlers.
50  *
51  * @author Cedric Boon - Initial contribution
52  */
53 @NonNullByDefault
54 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.velbus")
55 public class VelbusHandlerFactory extends BaseThingHandlerFactory {
56     private final SerialPortManager serialPortManager;
57
58     @Activate
59     public VelbusHandlerFactory(final @Reference SerialPortManager serialPortManager) {
60         this.serialPortManager = serialPortManager;
61     }
62
63     @Override
64     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
65         return BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID) || SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
66     }
67
68     @Override
69     protected @Nullable ThingHandler createHandler(Thing thing) {
70         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
71         ThingHandler thingHandler = null;
72
73         if (BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID)) {
74             VelbusBridgeHandler velbusBridgeHandler = thingTypeUID.equals(NETWORK_BRIDGE_THING_TYPE)
75                     ? new VelbusNetworkBridgeHandler((Bridge) thing)
76                     : new VelbusSerialBridgeHandler((Bridge) thing, serialPortManager);
77             thingHandler = velbusBridgeHandler;
78         } else if (VelbusRelayHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
79             thingHandler = new VelbusRelayHandler(thing);
80         } else if (VelbusDimmerHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
81             thingHandler = new VelbusDimmerHandler(thing);
82         } else if (VelbusBlindsHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
83             thingHandler = new VelbusBlindsHandler(thing);
84         } else if (VelbusSensorHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
85             thingHandler = new VelbusSensorHandler(thing);
86         } else if (VelbusSensorWithAlarmClockHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
87             thingHandler = new VelbusSensorWithAlarmClockHandler(thing);
88         } else if (VelbusVMBMeteoHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
89             thingHandler = new VelbusVMBMeteoHandler(thing);
90         } else if (VelbusVMBGPHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
91             thingHandler = new VelbusVMBGPHandler(thing);
92         } else if (VelbusVMBGPOHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
93             thingHandler = new VelbusVMBGPOHandler(thing);
94         } else if (VelbusVMBPIROHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
95             thingHandler = new VelbusVMBPIROHandler(thing);
96         } else if (VelbusVMB7INHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
97             thingHandler = new VelbusVMB7INHandler(thing);
98         } else if (VelbusVMBELHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
99             thingHandler = new VelbusVMBELHandler(thing);
100         } else if (VelbusVMBELOHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
101             thingHandler = new VelbusVMBELOHandler(thing);
102         } else if (VelbusVMB4ANHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
103             thingHandler = new VelbusVMB4ANHandler(thing);
104         } else if (VelbusVMB1TSHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
105             thingHandler = new VelbusVMB1TSHandler(thing);
106         }
107
108         return thingHandler;
109     }
110 }