]> git.basschouten.com Git - openhab-addons.git/blob
012019a7236fb272cfb034c038152152524e76df
[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.caddx.internal.factory;
14
15 import static org.openhab.binding.caddx.internal.CaddxBindingConstants.SUPPORTED_THING_TYPES_UIDS;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.caddx.internal.CaddxBindingConstants;
20 import org.openhab.binding.caddx.internal.handler.CaddxBridgeHandler;
21 import org.openhab.binding.caddx.internal.handler.ThingHandlerKeypad;
22 import org.openhab.binding.caddx.internal.handler.ThingHandlerPanel;
23 import org.openhab.binding.caddx.internal.handler.ThingHandlerPartition;
24 import org.openhab.binding.caddx.internal.handler.ThingHandlerZone;
25 import org.openhab.core.io.transport.serial.SerialPortManager;
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.Activate;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * The {@link CaddxHandlerFactory} is responsible for creating things and thing
40  * handlers.
41  *
42  * @author Georgios Moutsos - Initial contribution
43  */
44 @Component(configurationPid = "binding.caddx", service = ThingHandlerFactory.class)
45 @NonNullByDefault
46 public class CaddxHandlerFactory extends BaseThingHandlerFactory {
47     private final Logger logger = LoggerFactory.getLogger(CaddxHandlerFactory.class);
48     private final SerialPortManager portManager;
49
50     @Activate
51     public CaddxHandlerFactory(@Reference SerialPortManager portManager) {
52         this.portManager = portManager;
53     }
54
55     @Override
56     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
58     }
59
60     @Override
61     protected @Nullable ThingHandler createHandler(Thing thing) {
62         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
63
64         if (thingTypeUID.equals(CaddxBindingConstants.CADDXBRIDGE_THING_TYPE)) {
65             return new CaddxBridgeHandler(portManager, (Bridge) thing);
66         } else if (thingTypeUID.equals(CaddxBindingConstants.PANEL_THING_TYPE)) {
67             return new ThingHandlerPanel(thing);
68         } else if (thingTypeUID.equals(CaddxBindingConstants.PARTITION_THING_TYPE)) {
69             return new ThingHandlerPartition(thing);
70         } else if (thingTypeUID.equals(CaddxBindingConstants.ZONE_THING_TYPE)) {
71             return new ThingHandlerZone(thing);
72         } else if (thingTypeUID.equals(CaddxBindingConstants.KEYPAD_THING_TYPE)) {
73             return new ThingHandlerKeypad(thing);
74         } else {
75             logger.debug("createHandler(): ThingHandler not found for {}", thingTypeUID);
76
77             return null;
78         }
79     }
80 }