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.caddx.internal.factory;
15 import static org.openhab.binding.caddx.internal.CaddxBindingConstants.SUPPORTED_THING_TYPES_UIDS;
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;
39 * The {@link CaddxHandlerFactory} is responsible for creating things and thing
42 * @author Georgios Moutsos - Initial contribution
44 @Component(configurationPid = "binding.caddx", service = ThingHandlerFactory.class)
46 public class CaddxHandlerFactory extends BaseThingHandlerFactory {
47 private final Logger logger = LoggerFactory.getLogger(CaddxHandlerFactory.class);
48 private final SerialPortManager portManager;
51 public CaddxHandlerFactory(@Reference SerialPortManager portManager) {
52 this.portManager = portManager;
56 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
57 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
61 protected @Nullable ThingHandler createHandler(Thing thing) {
62 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);
75 logger.debug("createHandler(): ThingHandler not found for {}", thingTypeUID);