2 * Copyright (c) 2010-2023 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.plclogo.internal;
15 import static org.openhab.binding.plclogo.internal.PLCLogoBindingConstants.*;
17 import java.util.Collections;
18 import java.util.HashSet;
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;
38 * The {@link PLCLogoHandlerFactory} is responsible for creating things and
39 * thing handlers supported by PLCLogo binding.
41 * @author Alexander Falkenstern - Initial contribution
44 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.plclogo")
45 public class PLCLogoHandlerFactory extends BaseThingHandlerFactory {
47 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS;
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);
62 public PLCLogoHandlerFactory() {
66 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
71 protected @Nullable ThingHandler createHandler(Thing thing) {
72 if (THING_TYPE_DEVICE.equals(thing.getThingTypeUID()) && (thing instanceof Bridge)) {
73 return new PLCBridgeHandler((Bridge) thing);
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);