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.upnpcontrol.internal.discovery;
15 import static org.openhab.binding.upnpcontrol.internal.UpnpControlBindingConstants.*;
17 import java.util.HashMap;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.jupnp.model.meta.RemoteDevice;
24 import org.openhab.core.config.discovery.DiscoveryResult;
25 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
26 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.ThingUID;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
35 * @author Mark Herwege - Initial contribution
37 @Component(service = { UpnpDiscoveryParticipant.class })
39 public class UpnpControlDiscoveryParticipant implements UpnpDiscoveryParticipant {
41 private final Logger logger = LoggerFactory.getLogger(getClass());
44 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
45 return SUPPORTED_THING_TYPES_UIDS;
49 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
50 DiscoveryResult result = null;
51 ThingUID thingUid = getThingUID(device);
52 if (thingUid != null) {
53 String label = device.getDetails().getFriendlyName().isEmpty() ? device.getDisplayString()
54 : device.getDetails().getFriendlyName();
55 Map<String, Object> properties = new HashMap<>();
56 properties.put("ipAddress", device.getIdentity().getDescriptorURL().getHost());
57 properties.put("udn", device.getIdentity().getUdn().getIdentifierString());
58 result = DiscoveryResultBuilder.create(thingUid).withLabel(label).withProperties(properties)
59 .withRepresentationProperty("udn").build();
65 public @Nullable ThingUID getThingUID(RemoteDevice device) {
66 ThingUID result = null;
67 String deviceType = device.getType().getType();
68 String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
69 String model = device.getDetails().getModelDetails().getModelName();
70 String serialNumber = device.getDetails().getSerialNumber();
72 logger.debug("Device type {}, manufacturer {}, model {}, SN# {}", deviceType, manufacturer, model,
75 if (deviceType.equalsIgnoreCase("MediaRenderer")) {
76 this.logger.debug("Media renderer found: {}, {}", manufacturer, model);
77 ThingTypeUID thingTypeUID = THING_TYPE_RENDERER;
78 result = new ThingUID(thingTypeUID, device.getIdentity().getUdn().getIdentifierString());
79 } else if (deviceType.equalsIgnoreCase("MediaServer")) {
80 this.logger.debug("Media server found: {}, {}", manufacturer, model);
81 ThingTypeUID thingTypeUID = THING_TYPE_SERVER;
82 result = new ThingUID(thingTypeUID, device.getIdentity().getUdn().getIdentifierString());