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.deconz.internal.discovery;
15 import static org.openhab.binding.deconz.internal.BindingConstants.*;
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.ManufacturerDetails;
27 import org.jupnp.model.meta.RemoteDevice;
28 import org.openhab.core.config.discovery.DiscoveryResult;
29 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
30 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.openhab.core.thing.ThingUID;
33 import org.osgi.service.component.annotations.Component;
36 * Discover deCONZ software instances. They announce themselves as HUE bridges,
37 * and their REST API is compatible to HUE bridges. But they also provide a websocket
38 * real-time channel for sensors.
40 * We check for the manufacturer string of "dresden elektronik".
42 * @author David Graeff - Initial contribution
45 @Component(service = UpnpDiscoveryParticipant.class)
46 public class BridgeDiscoveryParticipant implements UpnpDiscoveryParticipant {
49 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
50 return Set.of(BRIDGE_TYPE);
54 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
55 ThingUID uid = getThingUID(device);
59 URL descriptorURL = device.getIdentity().getDescriptorURL();
60 String udn = device.getIdentity().getUdn().getIdentifierString();
62 // Friendly name is like "name (host)"
63 String name = device.getDetails().getFriendlyName();
64 // Cut out the pure name
65 if (name.indexOf('(') - 1 > 0) {
66 name = name.substring(0, name.indexOf('(') - 1);
69 String host = descriptorURL.getHost();
70 int port = descriptorURL.getPort();
71 name = name + " (" + host + ":" + port + ")";
73 Map<String, Object> properties = new TreeMap<>();
75 properties.put(CONFIG_HOST, host);
76 properties.put(CONFIG_HTTP_PORT, port);
77 properties.put(PROPERTY_UDN, udn);
79 return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(name)
80 .withRepresentationProperty(PROPERTY_UDN).build();
84 public @Nullable ThingUID getThingUID(RemoteDevice device) {
85 DeviceDetails details = device.getDetails();
86 if (details != null) {
87 ManufacturerDetails manufacturerDetails = details.getManufacturerDetails();
88 if (manufacturerDetails != null) {
89 URI manufacturerUri = manufacturerDetails.getManufacturerURI();
90 if ((manufacturerUri != null && manufacturerUri.toString().contains("dresden"))
91 || "dresden elektronik".equals(manufacturerDetails.getManufacturer())) {
92 return new ThingUID(BRIDGE_TYPE, details.getSerialNumber());