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.plugwise.internal;
15 import static org.openhab.binding.plugwise.internal.PlugwiseBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.plugwise.internal.handler.PlugwiseRelayDeviceHandler;
20 import org.openhab.binding.plugwise.internal.handler.PlugwiseScanHandler;
21 import org.openhab.binding.plugwise.internal.handler.PlugwiseSenseHandler;
22 import org.openhab.binding.plugwise.internal.handler.PlugwiseStickHandler;
23 import org.openhab.binding.plugwise.internal.handler.PlugwiseSwitchHandler;
24 import org.openhab.core.io.transport.serial.SerialPortManager;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Activate;
32 import org.osgi.service.component.annotations.Component;
33 import org.osgi.service.component.annotations.Reference;
36 * The {@link PlugwiseHandlerFactory} is responsible for creating Plugwise things and thing handlers.
38 * @author Wouter Born - Initial contribution
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.plugwise")
42 public class PlugwiseHandlerFactory extends BaseThingHandlerFactory {
44 private final SerialPortManager serialPortManager;
47 public PlugwiseHandlerFactory(final @Reference SerialPortManager serialPortManager) {
48 this.serialPortManager = serialPortManager;
52 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
53 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
57 protected @Nullable ThingHandler createHandler(Thing thing) {
58 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60 if (thingTypeUID.equals(THING_TYPE_STICK)) {
61 return new PlugwiseStickHandler((Bridge) thing, serialPortManager);
62 } else if (thingTypeUID.equals(THING_TYPE_CIRCLE) || thingTypeUID.equals(THING_TYPE_CIRCLE_PLUS)
63 || thingTypeUID.equals(THING_TYPE_STEALTH)) {
64 return new PlugwiseRelayDeviceHandler(thing);
65 } else if (thingTypeUID.equals(THING_TYPE_SCAN)) {
66 return new PlugwiseScanHandler(thing);
67 } else if (thingTypeUID.equals(THING_TYPE_SENSE)) {
68 return new PlugwiseSenseHandler(thing);
69 } else if (thingTypeUID.equals(THING_TYPE_SWITCH)) {
70 return new PlugwiseSwitchHandler(thing);