2 * Copyright (c) 2010-2021 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.tellstick.internal;
15 import static org.openhab.binding.tellstick.internal.TellstickBindingConstants.*;
17 import java.util.Hashtable;
19 import org.openhab.binding.tellstick.internal.core.TelldusCoreBridgeHandler;
20 import org.openhab.binding.tellstick.internal.discovery.TellstickDiscoveryService;
21 import org.openhab.binding.tellstick.internal.handler.TelldusBridgeHandler;
22 import org.openhab.binding.tellstick.internal.handler.TelldusDevicesHandler;
23 import org.openhab.binding.tellstick.internal.live.TelldusLiveBridgeHandler;
24 import org.openhab.core.config.discovery.DiscoveryService;
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.Component;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * The {@link TellstickHandlerFactory} is responsible for creating things and thing
39 * @author Jarle Hjortland - Initial contribution
41 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.tellstick")
42 public class TellstickHandlerFactory extends BaseThingHandlerFactory {
43 private final Logger logger = LoggerFactory.getLogger(TellstickHandlerFactory.class);
44 private TellstickDiscoveryService discoveryService = null;
47 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
48 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
51 private void registerDeviceDiscoveryService(TelldusBridgeHandler tellstickBridgeHandler) {
52 if (discoveryService == null) {
53 discoveryService = new TellstickDiscoveryService(tellstickBridgeHandler);
54 discoveryService.activate();
55 bundleContext.registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>());
57 discoveryService.addBridgeHandler(tellstickBridgeHandler);
62 protected ThingHandler createHandler(Thing thing) {
63 if (thing.getThingTypeUID().equals(TELLDUSCOREBRIDGE_THING_TYPE)) {
64 TelldusCoreBridgeHandler handler = new TelldusCoreBridgeHandler((Bridge) thing);
65 registerDeviceDiscoveryService(handler);
67 } else if (thing.getThingTypeUID().equals(TELLDUSLIVEBRIDGE_THING_TYPE)) {
68 TelldusLiveBridgeHandler handler = new TelldusLiveBridgeHandler((Bridge) thing);
69 registerDeviceDiscoveryService(handler);
71 } else if (supportsThingType(thing.getThingTypeUID())) {
72 return new TelldusDevicesHandler(thing);
74 logger.debug("ThingHandler not found for {}", thing.getThingTypeUID());