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.asuswrt.internal;
15 import static org.openhab.binding.asuswrt.internal.constants.AsuswrtBindingConstants.PROPERTY_HOSTNAME;
16 import static org.openhab.binding.asuswrt.internal.constants.AsuswrtBindingConstants.THING_TYPE_ROUTER;
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.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.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.ThingUID;
32 import org.osgi.service.component.annotations.Component;
35 * The {@link AsuswrtDiscoveryParticipant} discovers the ASUS routers using UPnP.
37 * @author Wouter Born - Initial contribution
40 @Component(service = UpnpDiscoveryParticipant.class, configurationPid = "discovery.asuswrt")
41 public class AsuswrtDiscoveryParticipant implements UpnpDiscoveryParticipant {
43 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
44 return Set.of(THING_TYPE_ROUTER);
48 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
49 ThingUID uid = getThingUID(device);
54 DeviceDetails details = device.getDetails();
56 String host = details.getPresentationURI().getHost();
57 String model = details.getModelDetails().getModelNumber();
59 Map<String, Object> properties = new HashMap<>();
60 properties.put(PROPERTY_HOSTNAME, host);
61 properties.put(Thing.PROPERTY_VENDOR, details.getManufacturerDetails().getManufacturer());
62 properties.put(Thing.PROPERTY_MODEL_ID, model);
63 properties.put(Thing.PROPERTY_MAC_ADDRESS, details.getSerialNumber());
65 String label = String.format("ASUS %s Wireless Router (%s)", model, host);
67 return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
68 .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).build();
72 public @Nullable ThingUID getThingUID(RemoteDevice device) {
73 DeviceDetails details = device.getDetails();
74 String modelName = details.getModelDetails().getModelName();
75 String modelManufacturer = details.getManufacturerDetails().getManufacturer();
76 if (modelManufacturer.toUpperCase().contains("ASUS") && ("ASUS Wireless Router".equalsIgnoreCase(modelName))) {
77 return new ThingUID(THING_TYPE_ROUTER, details.getSerialNumber().replace(':', '-'));