2 * Copyright (c) 2010-2024 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.velbus.internal;
15 import static org.openhab.binding.velbus.internal.VelbusBindingConstants.*;
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.VelbusRelayWithInputHandler;
25 import org.openhab.binding.velbus.internal.handler.VelbusSensorHandler;
26 import org.openhab.binding.velbus.internal.handler.VelbusSensorWithAlarmClockHandler;
27 import org.openhab.binding.velbus.internal.handler.VelbusSerialBridgeHandler;
28 import org.openhab.binding.velbus.internal.handler.VelbusVMB1TSHandler;
29 import org.openhab.binding.velbus.internal.handler.VelbusVMB4ANHandler;
30 import org.openhab.binding.velbus.internal.handler.VelbusVMB7INHandler;
31 import org.openhab.binding.velbus.internal.handler.VelbusVMBELHandler;
32 import org.openhab.binding.velbus.internal.handler.VelbusVMBELOHandler;
33 import org.openhab.binding.velbus.internal.handler.VelbusVMBGPHandler;
34 import org.openhab.binding.velbus.internal.handler.VelbusVMBGPOHandler;
35 import org.openhab.binding.velbus.internal.handler.VelbusVMBMeteoHandler;
36 import org.openhab.binding.velbus.internal.handler.VelbusVMBPIROHandler;
37 import org.openhab.core.io.transport.serial.SerialPortManager;
38 import org.openhab.core.thing.Bridge;
39 import org.openhab.core.thing.Thing;
40 import org.openhab.core.thing.ThingTypeUID;
41 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
42 import org.openhab.core.thing.binding.ThingHandler;
43 import org.openhab.core.thing.binding.ThingHandlerFactory;
44 import org.osgi.service.component.annotations.Activate;
45 import org.osgi.service.component.annotations.Component;
46 import org.osgi.service.component.annotations.Reference;
49 * The {@link VelbusHandlerFactory} is responsible for creating things and thing
52 * @author Cedric Boon - Initial contribution
55 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.velbus")
56 public class VelbusHandlerFactory extends BaseThingHandlerFactory {
57 private final SerialPortManager serialPortManager;
60 public VelbusHandlerFactory(final @Reference SerialPortManager serialPortManager) {
61 this.serialPortManager = serialPortManager;
65 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
66 return BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID) || SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
70 protected @Nullable ThingHandler createHandler(Thing thing) {
71 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
72 ThingHandler thingHandler = null;
74 if (BRIDGE_THING_TYPES_UIDS.contains(thingTypeUID)) {
75 VelbusBridgeHandler velbusBridgeHandler = thingTypeUID.equals(NETWORK_BRIDGE_THING_TYPE)
76 ? new VelbusNetworkBridgeHandler((Bridge) thing)
77 : new VelbusSerialBridgeHandler((Bridge) thing, serialPortManager);
78 thingHandler = velbusBridgeHandler;
79 } else if (VelbusRelayHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
80 thingHandler = new VelbusRelayHandler(thing);
81 } else if (VelbusRelayWithInputHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
82 thingHandler = new VelbusRelayWithInputHandler(thing);
83 } else if (VelbusDimmerHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
84 thingHandler = new VelbusDimmerHandler(thing);
85 } else if (VelbusBlindsHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
86 thingHandler = new VelbusBlindsHandler(thing);
87 } else if (VelbusSensorHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
88 thingHandler = new VelbusSensorHandler(thing);
89 } else if (VelbusSensorWithAlarmClockHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
90 thingHandler = new VelbusSensorWithAlarmClockHandler(thing);
91 } else if (VelbusVMBMeteoHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
92 thingHandler = new VelbusVMBMeteoHandler(thing);
93 } else if (VelbusVMBGPHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
94 thingHandler = new VelbusVMBGPHandler(thing);
95 } else if (VelbusVMBGPOHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
96 thingHandler = new VelbusVMBGPOHandler(thing);
97 } else if (VelbusVMBPIROHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
98 thingHandler = new VelbusVMBPIROHandler(thing);
99 } else if (VelbusVMB7INHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
100 thingHandler = new VelbusVMB7INHandler(thing);
101 } else if (VelbusVMBELHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
102 thingHandler = new VelbusVMBELHandler(thing);
103 } else if (VelbusVMBELOHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
104 thingHandler = new VelbusVMBELOHandler(thing);
105 } else if (VelbusVMB4ANHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
106 thingHandler = new VelbusVMB4ANHandler(thing);
107 } else if (VelbusVMB1TSHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
108 thingHandler = new VelbusVMB1TSHandler(thing);