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.tellstick.internal.discovery;
15 import java.util.HashMap;
16 import java.util.List;
20 import org.openhab.binding.tellstick.internal.TellstickBindingConstants;
21 import org.openhab.core.config.discovery.AbstractDiscoveryService;
22 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
23 import org.openhab.core.config.discovery.DiscoveryService;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.ThingUID;
26 import org.osgi.service.component.annotations.Component;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.tellstick.device.TellstickController;
32 * The {@link TellstickBridgeDiscovery} is responsible for discovering new Telldus gateway devices on the network
34 * @author Jarle Hjortland - Initial contribution
37 @Component(service = DiscoveryService.class, configurationPid = "discovery.tellstick")
38 public class TellstickBridgeDiscovery extends AbstractDiscoveryService {
40 private final Logger logger = LoggerFactory.getLogger(TellstickBridgeDiscovery.class);
42 static boolean discoveryRunning = false;
43 static boolean initilized = false;
45 public TellstickBridgeDiscovery() {
46 super(TellstickBindingConstants.SUPPORTED_BRIDGE_THING_TYPES_UIDS, 15);
50 public Set<ThingTypeUID> getSupportedThingTypes() {
51 return TellstickBindingConstants.SUPPORTED_BRIDGE_THING_TYPES_UIDS;
55 public void startScan() {
60 protected void startBackgroundDiscovery() {
65 public boolean isBackgroundDiscoveryEnabled() {
69 private synchronized void discoverController() {
70 if (!discoveryRunning) {
71 discoveryRunning = true;
76 private void listBridge() {
78 List<TellstickController> cntrls = TellstickController.getControllers();
79 for (TellstickController contrl : cntrls) {
80 discoveryResultSubmission(contrl);
82 } catch (UnsatisfiedLinkError e) {
84 "Could not load telldus core, please make sure Telldus is installed and correct 32/64 bit java.",
86 } catch (NoClassDefFoundError e) {
88 "Could not load telldus core, please make sure Telldus is installed and correct 32/64 bit java.",
92 discoveryRunning = false;
96 private void discoveryResultSubmission(TellstickController controller) {
97 if (controller != null && controller.isOnline()) {
98 logger.trace("Adding new Telldus Controller {}", controller);
99 Map<String, Object> properties = new HashMap<>(2);
100 ThingUID uid = new ThingUID(TellstickBindingConstants.TELLDUSCOREBRIDGE_THING_TYPE,
101 Integer.toString(controller.getId()));
102 thingDiscovered(DiscoveryResultBuilder.create(uid).withProperties(properties)
103 .withLabel(controller.getType().name() + ": " + controller.getName()).build());