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.heos.internal.discovery;
15 import static org.openhab.binding.heos.internal.HeosBindingConstants.*;
17 import java.util.Collections;
18 import java.util.HashMap;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.jupnp.model.meta.DeviceDetails;
25 import org.jupnp.model.meta.ModelDetails;
26 import org.jupnp.model.meta.RemoteDevice;
27 import org.openhab.binding.heos.internal.configuration.BridgeConfiguration;
28 import org.openhab.core.config.discovery.DiscoveryResult;
29 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
30 import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant;
31 import org.openhab.core.thing.Thing;
32 import org.openhab.core.thing.ThingTypeUID;
33 import org.openhab.core.thing.ThingUID;
34 import org.osgi.service.component.annotations.Component;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * The {@link HeosDiscoveryParticipant} discovers the HEOS Player of the
40 * network via an UPnP interface.
42 * @author Johannes Einig - Initial contribution
45 @Component(service = UpnpDiscoveryParticipant.class, configurationPid = "discovery.heos")
46 public class HeosDiscoveryParticipant implements UpnpDiscoveryParticipant {
47 private final Logger logger = LoggerFactory.getLogger(HeosDiscoveryParticipant.class);
50 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
51 return Collections.singleton(THING_TYPE_BRIDGE);
55 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
56 ThingUID uid = getThingUID(device);
58 Map<String, Object> properties = new HashMap<>();
59 properties.put(Thing.PROPERTY_VENDOR, device.getDetails().getManufacturerDetails().getManufacturer());
60 properties.put(Thing.PROPERTY_MODEL_ID, getModel(device.getDetails().getModelDetails()));
61 properties.put(Thing.PROPERTY_SERIAL_NUMBER, device.getDetails().getSerialNumber());
62 properties.put(BridgeConfiguration.IP_ADDRESS, device.getIdentity().getDescriptorURL().getHost());
63 properties.put(PROP_NAME, device.getDetails().getFriendlyName());
64 DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
65 .withLabel(" Bridge - " + device.getDetails().getFriendlyName())
66 .withRepresentationProperty(Thing.PROPERTY_VENDOR).build();
67 logger.debug("Found HEOS device with UID: {}", uid.getAsString());
73 private String getModel(ModelDetails modelDetails) {
74 return String.format("%s (%s)", modelDetails.getModelName(), modelDetails.getModelNumber());
78 public @Nullable ThingUID getThingUID(RemoteDevice device) {
79 DeviceDetails details = device.getDetails();
80 String modelName = details.getModelDetails().getModelName();
81 String modelManufacturer = details.getManufacturerDetails().getManufacturer();
82 if ("Denon".equals(modelManufacturer)
83 && (modelName.startsWith("HEOS") || modelName.endsWith("H") || modelName.contains("Home"))) {
84 String deviceType = device.getType().getType();
85 if (deviceType.startsWith("ACT") || deviceType.startsWith("Aios")) {
86 return new ThingUID(THING_TYPE_BRIDGE, device.getIdentity().getUdn().getIdentifierString());