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.loxone.internal;
15 import java.util.HashMap;
19 import org.jupnp.model.meta.DeviceDetails;
20 import org.jupnp.model.meta.RemoteDevice;
21 import org.openhab.core.config.discovery.DiscoveryResult;
22 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
23 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
27 import org.osgi.service.component.annotations.Component;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link LxDiscoveryParticipant} class creates Miniserver things.
33 * It analyzes UPNP devices discovered by the framework and if Loxone Miniserver is found,
34 * a new thing discovery is reported, which in turn will result in creating a {@link Thing}
35 * and subsequently a new {@link LxServerHandler} object.
37 * @author Pawel Pieczul - Initial contribution
41 public class LxDiscoveryParticipant implements UpnpDiscoveryParticipant {
43 private final Logger logger = LoggerFactory.getLogger(LxDiscoveryParticipant.class);
46 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
47 return LxServerHandler.SUPPORTED_THING_TYPES_UIDS;
51 public DiscoveryResult createResult(RemoteDevice device) {
52 ThingUID uid = getThingUID(device);
54 Map<String, Object> properties = new HashMap<>(2);
56 // After correct Thing UID is created, we have confidence that all following parameters exist and we don't
57 // need to check for null objects here in the device details
58 DeviceDetails details = device.getDetails();
59 String serial = details.getSerialNumber();
60 String host = details.getPresentationURI().getHost();
61 String label = details.getFriendlyName() + " @ " + host;
62 int port = details.getPresentationURI().getPort();
63 String vendor = details.getManufacturerDetails().getManufacturer();
64 String model = details.getModelDetails().getModelName();
66 logger.debug("Creating discovery result for serial {} label {} port {}", serial, label, port);
67 properties.put(LxBindingConstants.MINISERVER_PARAM_HOST, host);
68 properties.put(LxBindingConstants.MINISERVER_PARAM_PORT, port);
69 properties.put(Thing.PROPERTY_VENDOR, vendor);
70 properties.put(Thing.PROPERTY_MODEL_ID, model);
71 properties.put(Thing.PROPERTY_SERIAL_NUMBER, serial);
73 return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
74 .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).build();
80 public ThingUID getThingUID(RemoteDevice device) {
81 String manufacturer = device.getDetails().getManufacturerDetails().getManufacturer();
82 if (manufacturer != null && manufacturer.toLowerCase().contains("loxone")) {
83 String model = device.getDetails().getModelDetails().getModelName();
84 if (model != null && model.toLowerCase().contentEquals("loxone miniserver")) {
85 String serial = device.getDetails().getSerialNumber();
87 serial = device.getIdentity().getUdn().getIdentifierString();
90 return new ThingUID(LxBindingConstants.THING_TYPE_MINISERVER, serial);