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