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.elerotransmitterstick.internal;
15 import static org.openhab.binding.elerotransmitterstick.internal.EleroTransmitterStickBindingConstants.*;
17 import java.util.Collections;
18 import java.util.HashMap;
19 import java.util.Hashtable;
22 import java.util.stream.Collectors;
23 import java.util.stream.Stream;
25 import org.eclipse.jdt.annotation.NonNullByDefault;
26 import org.eclipse.jdt.annotation.Nullable;
27 import org.openhab.binding.elerotransmitterstick.internal.discovery.EleroChannelDiscoveryService;
28 import org.openhab.binding.elerotransmitterstick.internal.handler.EleroChannelHandler;
29 import org.openhab.binding.elerotransmitterstick.internal.handler.EleroTransmitterStickHandler;
30 import org.openhab.core.config.discovery.DiscoveryService;
31 import org.openhab.core.io.transport.serial.SerialPortManager;
32 import org.openhab.core.thing.Bridge;
33 import org.openhab.core.thing.Thing;
34 import org.openhab.core.thing.ThingTypeUID;
35 import org.openhab.core.thing.ThingUID;
36 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
37 import org.openhab.core.thing.binding.ThingHandler;
38 import org.openhab.core.thing.binding.ThingHandlerFactory;
39 import org.osgi.framework.ServiceRegistration;
40 import org.osgi.service.component.annotations.Activate;
41 import org.osgi.service.component.annotations.Component;
42 import org.osgi.service.component.annotations.Reference;
45 * The {@link EleroTransmitterStickHandlerFactory} is responsible for creating things and thing
48 * @author Volker Bier - Initial contribution
51 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.elerotransmitterstick")
52 public class EleroTransmitterStickHandlerFactory extends BaseThingHandlerFactory {
54 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
55 .unmodifiableSet(Stream.of(THING_TYPE_STICK, THING_TYPE_ELERO_CHANNEL).collect(Collectors.toSet()));
57 private final Map<ThingUID, ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();
59 private final SerialPortManager serialPortManager;
62 public EleroTransmitterStickHandlerFactory(final @Reference SerialPortManager serialPortManager) {
63 this.serialPortManager = serialPortManager;
67 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
68 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
72 protected @Nullable ThingHandler createHandler(Thing thing) {
73 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
75 if (thingTypeUID.equals(THING_TYPE_STICK)) {
76 EleroTransmitterStickHandler bridgeHandler = new EleroTransmitterStickHandler((Bridge) thing,
79 EleroChannelDiscoveryService discoveryService = new EleroChannelDiscoveryService(bridgeHandler);
80 discoveryServiceRegs.put(bridgeHandler.getThing().getUID(), bundleContext
81 .registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>()));
84 } else if (thingTypeUID.equals(THING_TYPE_ELERO_CHANNEL)) {
85 return new EleroChannelHandler(thing);