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