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.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.jupnp.model.meta.RemoteDevice;
26 import org.openhab.core.config.discovery.DiscoveryResult;
27 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
28 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.ThingUID;
31 import org.osgi.service.component.annotations.Component;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * The {@link LaMetricTimeDiscoveryParticipant} is responsible for processing the
37 * results of searched UPnP devices
39 * @author Gregory Moyer - Initial contribution
43 public class LaMetricTimeDiscoveryParticipant implements UpnpDiscoveryParticipant {
45 private Logger logger = LoggerFactory.getLogger(LaMetricTimeDiscoveryParticipant.class);
48 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
49 return Collections.singleton(THING_TYPE_DEVICE);
53 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
54 ThingUID uid = getThingUID(device);
59 Map<String, Object> properties = new HashMap<>(1);
60 properties.put(HOST, device.getIdentity().getDescriptorURL().getHost());
62 String friendlyName = device.getDetails().getFriendlyName();
63 DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(friendlyName)
66 logger.debug("Created a DiscoveryResult for device '{}' with serial number '{}'",
67 device.getDetails().getModelDetails().getModelName(), device.getDetails().getSerialNumber());
73 public @Nullable ThingUID getThingUID(RemoteDevice device) {
75 String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
76 String modelName = device.getDetails().getModelDetails().getModelName();
78 if (!manufacturer.toUpperCase().contains("LAMETRIC")
79 || !modelName.toUpperCase().contains("LAMETRIC TIME")) {
83 String serialNumber = device.getDetails().getSerialNumber();
84 logger.debug("Discovered '{}' model '{}' thing with serial number '{}'",
85 device.getDetails().getFriendlyName(), modelName, serialNumber);
87 return new ThingUID(THING_TYPE_DEVICE, serialNumber);
88 } catch (Exception e) {
89 // device was not what we expected
90 logger.debug("Discovery hit an unexpected error", e);