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.autelis.internal.discovery;
16 import java.util.HashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.jupnp.model.meta.RemoteDevice;
23 import org.openhab.binding.autelis.internal.AutelisBindingConstants;
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;
35 * Discovery Service for Autelis Pool Controllers.
37 * @author Dan Cunningham - Initial contribution
42 public class AutelisDiscoveryParticipant implements UpnpDiscoveryParticipant {
44 private final Logger logger = LoggerFactory.getLogger(AutelisDiscoveryParticipant.class);
46 private static final String MANUFACTURER = "autelis";
47 private static final String MODEL_PENTAIR = "pc100p";
48 private static final String MODEL_JANDY = "pc100j";
51 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
52 return AutelisBindingConstants.SUPPORTED_THING_TYPES_UIDS;
56 public @Nullable DiscoveryResult createResult(RemoteDevice device) {
57 ThingUID uid = getThingUID(device);
59 Map<String, Object> properties = new HashMap<>(3);
61 URL url = device.getDetails().getBaseURL();
62 String label = device.getDetails().getFriendlyName();
63 int port = url.getPort() > 0 ? url.getPort() : 80;
65 properties.put("host", url.getHost());
66 properties.put("user", "admin");
67 properties.put("password", "admin");
68 properties.put("port", Integer.valueOf(port));
70 DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label)
73 logger.debug("Created a DiscoveryResult for device '{}' with UDN '{}'",
74 device.getDetails().getFriendlyName(), device.getIdentity().getUdn().getIdentifierString());
82 public @Nullable ThingUID getThingUID(RemoteDevice device) {
83 if (device.getDetails().getManufacturerDetails().getManufacturer() != null
84 && device.getDetails().getModelDetails().getModelNumber() != null) {
85 logger.trace("UPNP {} : {}", device.getDetails().getManufacturerDetails().getManufacturer(),
86 device.getDetails().getModelDetails().getModelNumber());
87 if (device.getDetails().getManufacturerDetails().getManufacturer().toLowerCase().startsWith(MANUFACTURER)) {
88 logger.debug("Autelis Pool Control Found at {}", device.getDetails().getBaseURL());
89 String id = device.getIdentity().getUdn().getIdentifierString().replaceAll(":", "").toUpperCase();
90 if (device.getDetails().getModelDetails().getModelNumber().toLowerCase().startsWith(MODEL_PENTAIR)) {
91 return new ThingUID(AutelisBindingConstants.PENTAIR_THING_TYPE_UID, id);
93 if (device.getDetails().getModelDetails().getModelNumber().toLowerCase().startsWith(MODEL_JANDY)) {
94 return new ThingUID(AutelisBindingConstants.JANDY_THING_TYPE_UID, id);