]> git.basschouten.com Git - openhab-addons.git/blob
4351f2e72b87d48ece010b95fc4a0f3c4185baa4
[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.plclogo.internal;
14
15 import static org.openhab.binding.plclogo.internal.PLCLogoBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.HashSet;
19 import java.util.Set;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.plclogo.internal.handler.PLCAnalogHandler;
24 import org.openhab.binding.plclogo.internal.handler.PLCBridgeHandler;
25 import org.openhab.binding.plclogo.internal.handler.PLCDateTimeHandler;
26 import org.openhab.binding.plclogo.internal.handler.PLCDigitalHandler;
27 import org.openhab.binding.plclogo.internal.handler.PLCMemoryHandler;
28 import org.openhab.binding.plclogo.internal.handler.PLCPulseHandler;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
33 import org.openhab.core.thing.binding.ThingHandler;
34 import org.openhab.core.thing.binding.ThingHandlerFactory;
35 import org.osgi.service.component.annotations.Component;
36
37 /**
38  * The {@link PLCLogoHandlerFactory} is responsible for creating things and
39  * thing handlers supported by PLCLogo binding.
40  *
41  * @author Alexander Falkenstern - Initial contribution
42  */
43 @NonNullByDefault
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.plclogo")
45 public class PLCLogoHandlerFactory extends BaseThingHandlerFactory {
46
47     private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS;
48     static {
49         Set<ThingTypeUID> buffer = new HashSet<>();
50         buffer.add(THING_TYPE_DEVICE);
51         buffer.add(THING_TYPE_MEMORY);
52         buffer.add(THING_TYPE_ANALOG);
53         buffer.add(THING_TYPE_DIGITAL);
54         buffer.add(THING_TYPE_DATETIME);
55         buffer.add(THING_TYPE_PULSE);
56         SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(buffer);
57     }
58
59     /**
60      * Constructor.
61      */
62     public PLCLogoHandlerFactory() {
63     }
64
65     @Override
66     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68     }
69
70     @Override
71     protected @Nullable ThingHandler createHandler(Thing thing) {
72         if (THING_TYPE_DEVICE.equals(thing.getThingTypeUID()) && (thing instanceof Bridge bridge)) {
73             return new PLCBridgeHandler(bridge);
74         } else if (THING_TYPE_ANALOG.equals(thing.getThingTypeUID())) {
75             return new PLCAnalogHandler(thing);
76         } else if (THING_TYPE_DIGITAL.equals(thing.getThingTypeUID())) {
77             return new PLCDigitalHandler(thing);
78         } else if (THING_TYPE_DATETIME.equals(thing.getThingTypeUID())) {
79             return new PLCDateTimeHandler(thing);
80         } else if (THING_TYPE_MEMORY.equals(thing.getThingTypeUID())) {
81             return new PLCMemoryHandler(thing);
82         } else if (THING_TYPE_PULSE.equals(thing.getThingTypeUID())) {
83             return new PLCPulseHandler(thing);
84         }
85
86         return null;
87     }
88 }