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.lametrictime.internal.discovery;
15 import static org.openhab.binding.lametrictime.internal.LaMetricTimeBindingConstants.THING_TYPE_DEVICE;
16 import static org.openhab.binding.lametrictime.internal.config.LaMetricTimeConfiguration.HOST;
18 import java.util.Collections;
19 import java.util.HashMap;
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;
34 * The {@link LaMetricTimeDiscoveryParticipant} is responsible for processing the
35 * results of searched UPnP devices
37 * @author Gregory Moyer - Initial contribution
40 public class LaMetricTimeDiscoveryParticipant implements UpnpDiscoveryParticipant {
42 private Logger logger = LoggerFactory.getLogger(LaMetricTimeDiscoveryParticipant.class);
45 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
46 return Collections.singleton(THING_TYPE_DEVICE);
50 public DiscoveryResult createResult(RemoteDevice device) {
51 ThingUID uid = getThingUID(device);
56 Map<String, Object> properties = new HashMap<>(1);
57 properties.put(HOST, device.getIdentity().getDescriptorURL().getHost());
59 String friendlyName = device.getDetails().getFriendlyName();
60 DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(friendlyName)
63 logger.debug("Created a DiscoveryResult for device '{}' with serial number '{}'",
64 device.getDetails().getModelDetails().getModelName(), device.getDetails().getSerialNumber());
70 public ThingUID getThingUID(RemoteDevice device) {
72 String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
73 String modelName = device.getDetails().getModelDetails().getModelName();
75 if (!manufacturer.toUpperCase().contains("LAMETRIC")
76 || !modelName.toUpperCase().contains("LAMETRIC TIME")) {
80 String serialNumber = device.getDetails().getSerialNumber();
81 logger.debug("Discovered '{}' model '{}' thing with serial number '{}'",
82 device.getDetails().getFriendlyName(), modelName, serialNumber);
84 return new ThingUID(THING_TYPE_DEVICE, serialNumber);
85 } catch (Exception e) {
86 // device was not what we expected
87 logger.debug("Discovery hit an unexpected error", e);