2 * Copyright (c) 2010-2020 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.deconz.internal.discovery;
15 import static org.openhab.binding.deconz.internal.BindingConstants.*;
18 import java.util.Collections;
21 import java.util.TreeMap;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.jupnp.model.meta.DeviceDetails;
26 import org.jupnp.model.meta.RemoteDevice;
27 import org.openhab.core.config.discovery.DiscoveryResult;
28 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
29 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.ThingUID;
32 import org.osgi.service.component.annotations.Component;
35 * Discover deCONZ software instances. They announce themselves as HUE bridges,
36 * and their REST API is compatible to HUE bridges. But they also provide a websocket
37 * real-time channel for sensors.
39 * We check for the manufacturer string of "dresden elektronik".
41 * @author David Graeff - Initial contribution
44 @Component(service = UpnpDiscoveryParticipant.class)
45 public class BridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
48 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
49 return Collections.singleton(BRIDGE_TYPE);
53 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
54 ThingUID uid = getThingUID(device);
58 URL descriptorURL = device.getIdentity().getDescriptorURL();
59 String UDN = device.getIdentity().getUdn().getIdentifierString();
61 // Friendly name is like "name (host)"
62 String name = device.getDetails().getFriendlyName();
63 // Cut out the pure name
64 if (name.indexOf('(') - 1 > 0) {
65 name = name.substring(0, name.indexOf('(') - 1);
68 String host = descriptorURL.getHost();
69 int port = descriptorURL.getPort();
70 name = name + " (" + host + ":" + String.valueOf(port) + ")";
72 Map<String, Object> properties = new TreeMap<>();
74 properties.put(CONFIG_HOST, host);
75 properties.put(CONFIG_HTTP_PORT, port);
76 properties.put(PROPERTY_UDN, UDN);
78 return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(name)
79 .withRepresentationProperty(PROPERTY_UDN).build();
83 public @Nullable ThingUID getThingUID(RemoteDevice device) {
84 DeviceDetails details = device.getDetails();
85 if (details != null && details.getManufacturerDetails() != null
86 && "dresden elektronik".equals(details.getManufacturerDetails().getManufacturer())) {
87 return new ThingUID(BRIDGE_TYPE, details.getSerialNumber());