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.nikobus.internal;
15 import static org.openhab.binding.nikobus.internal.NikobusBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.nikobus.internal.handler.NikobusDimmerModuleHandler;
25 import org.openhab.binding.nikobus.internal.handler.NikobusPcLinkHandler;
26 import org.openhab.binding.nikobus.internal.handler.NikobusPushButtonHandler;
27 import org.openhab.binding.nikobus.internal.handler.NikobusRollershutterModuleHandler;
28 import org.openhab.binding.nikobus.internal.handler.NikobusSwitchModuleHandler;
29 import org.openhab.core.io.transport.serial.SerialPortManager;
30 import org.openhab.core.thing.Bridge;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
34 import org.openhab.core.thing.binding.ThingHandler;
35 import org.openhab.core.thing.binding.ThingHandlerFactory;
36 import org.osgi.service.component.annotations.Component;
37 import org.osgi.service.component.annotations.Reference;
40 * The {@link NikobusHandlerFactory} is responsible for creating things and thing
43 * @author Boris Krivonog - Initial contribution
46 @Component(configurationPid = "binding.nikobus", service = ThingHandlerFactory.class)
47 public class NikobusHandlerFactory extends BaseThingHandlerFactory {
49 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
50 .unmodifiableSet(Stream.of(BRIDGE_TYPE_PCLINK, THING_TYPE_PUSH_BUTTON, THING_TYPE_SWITCH_MODULE,
51 THING_TYPE_DIMMER_MODULE, THING_TYPE_ROLLERSHUTTER_MODULE).collect(Collectors.toSet()));
53 private @NonNullByDefault({}) SerialPortManager serialPortManager;
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 (BRIDGE_TYPE_PCLINK.equals(thingTypeUID)) {
65 return new NikobusPcLinkHandler((Bridge) thing, serialPortManager);
68 if (THING_TYPE_PUSH_BUTTON.equals(thingTypeUID)) {
69 return new NikobusPushButtonHandler(thing);
72 if (THING_TYPE_SWITCH_MODULE.equals(thingTypeUID)) {
73 return new NikobusSwitchModuleHandler(thing);
76 if (THING_TYPE_DIMMER_MODULE.equals(thingTypeUID)) {
77 return new NikobusDimmerModuleHandler(thing);
80 if (THING_TYPE_ROLLERSHUTTER_MODULE.equals(thingTypeUID)) {
81 return new NikobusRollershutterModuleHandler(thing);
88 protected void setSerialPortManager(final SerialPortManager serialPortManager) {
89 this.serialPortManager = serialPortManager;
92 protected void unsetSerialPortManager(final SerialPortManager serialPortManager) {
93 this.serialPortManager = null;