2 * Copyright (c) 2010-2024 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.kaleidescape.internal.discovery;
15 import static org.openhab.binding.kaleidescape.internal.KaleidescapeBindingConstants.*;
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;
34 * The {@link KaleidescapeDiscoveryParticipant} class discovers Strato/Encore line components automatically via UPnP.
36 * @author Michael Lobstein - Initial contribution
40 @Component(immediate = true)
41 public class KaleidescapeDiscoveryParticipant implements UpnpDiscoveryParticipant {
42 private final Logger logger = LoggerFactory.getLogger(KaleidescapeDiscoveryParticipant.class);
44 private static final String MANUFACTURER = "Kaleidescape";
47 private static final String ALTO = "Alto";
48 private static final String STRATO = "Strato";
51 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
52 return Set.of(THING_TYPE_ALTO, THING_TYPE_STRATO);
56 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
57 final ThingUID uid = getThingUID(device);
59 final Map<String, Object> properties = new HashMap<>(3);
62 if (device.getDetails().getFriendlyName() != null && !device.getDetails().getFriendlyName().isBlank()) {
63 label = device.getDetails().getFriendlyName();
65 label = device.getDetails().getModelDetails().getModelName();
68 properties.put(PROPERTY_UUID, uid.getId());
69 properties.put(PROPERTY_HOST_NAME, device.getIdentity().getDescriptorURL().getHost());
70 properties.put(PROPERTY_PORT_NUM, DEFAULT_API_PORT);
72 final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
73 .withRepresentationProperty(PROPERTY_UUID).withLabel(label).build();
75 logger.debug("Created a DiscoveryResult for device '{}' with UID '{}'", label, uid.getId());
83 public @Nullable ThingUID getThingUID(RemoteDevice device) {
84 if (device.getDetails().getManufacturerDetails().getManufacturer() != null
85 && device.getDetails().getModelDetails().getModelName() != null
86 && device.getDetails().getManufacturerDetails().getManufacturer().startsWith(MANUFACTURER)) {
87 final String modelName = device.getDetails().getModelDetails().getModelName();
88 final String id = device.getIdentity().getUdn().getIdentifierString().replace(":", EMPTY);
90 logger.debug("Kaleidescape {} with id {} found at {}", modelName, id,
91 device.getIdentity().getDescriptorURL().getHost());
94 logger.debug("Invalid UDN for Kaleidescape device: {}", device.toString());
98 if (modelName.contains(ALTO)) {
99 return new ThingUID(THING_TYPE_ALTO, id);
100 } else if (modelName.contains(STRATO)) {
101 return new ThingUID(THING_TYPE_STRATO, id);