2 * Copyright (c) 2010-2022 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.lgwebos.internal.discovery;
15 import static org.openhab.binding.lgwebos.internal.LGWebOSBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.jupnp.model.meta.RemoteDevice;
22 import org.openhab.core.config.discovery.DiscoveryResult;
23 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
24 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
25 import org.openhab.core.thing.Thing;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.ThingUID;
28 import org.osgi.service.component.annotations.Component;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * This Upnp Discovery participant add the ability to auto discover LG Web OS devices on the network.
34 * Some users choose to not use upnp. Therefore this can only play an optional role and help discover the device and its
37 * @author Sebastian Prehn - Initial contribution
40 @Component(service = UpnpDiscoveryParticipant.class, configurationPid = "discovery.lgwebos.upnp")
41 public class LGWebOSUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant {
43 private final Logger logger = LoggerFactory.getLogger(LGWebOSUpnpDiscoveryParticipant.class);
46 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
47 return SUPPORTED_THING_TYPES_UIDS;
51 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
52 ThingUID thingUID = getThingUID(device);
54 if (thingUID == null) {
58 String modelName = device.getDetails().getModelDetails().getModelName();
59 if (device.getDetails().getModelDetails().getModelNumber() != null) {
60 modelName += " " + device.getDetails().getModelDetails().getModelNumber();
63 return DiscoveryResultBuilder.create(thingUID).withLabel(device.getDetails().getFriendlyName())
64 .withProperty(PROPERTY_DEVICE_ID, device.getIdentity().getUdn().getIdentifierString())
65 .withProperty(CONFIG_HOST, device.getIdentity().getDescriptorURL().getHost())
66 .withProperty(Thing.PROPERTY_MODEL_ID, modelName)
67 .withProperty(Thing.PROPERTY_VENDOR, device.getDetails().getManufacturerDetails().getManufacturer())
68 .withRepresentationProperty(PROPERTY_DEVICE_ID).withThingType(THING_TYPE_WEBOSTV).build();
72 public @Nullable ThingUID getThingUID(RemoteDevice device) {
73 logger.trace("Discovered remote device {}", device);
74 if (device.findService(UPNP_SERVICE_TYPE) != null) {
75 logger.debug("Found LG WebOS TV: {}", device);
76 return new ThingUID(THING_TYPE_WEBOSTV, device.getIdentity().getUdn().getIdentifierString());