2 * Copyright (c) 2010-2022 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.etherrain.internal.discovery;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.etherrain.internal.EtherRainBindingConstants;
19 import org.openhab.binding.etherrain.internal.api.EtherRainCommunication;
20 import org.openhab.binding.etherrain.internal.api.EtherRainUdpResponse;
21 import org.openhab.core.config.discovery.AbstractDiscoveryService;
22 import org.openhab.core.config.discovery.DiscoveryResult;
23 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
24 import org.openhab.core.config.discovery.DiscoveryService;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
27 import org.osgi.service.component.annotations.Component;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link EtherrainDiscoveryService} class discovers Etherrain Device(s) and places them in the inbox.
34 * @author Joe Inkenbrandt - Initial contribution
37 @Component(service = DiscoveryService.class, configurationPid = "discovery.etherrain")
38 public class EtherrainDiscoveryService extends AbstractDiscoveryService {
40 private final Logger logger = LoggerFactory.getLogger(EtherrainDiscoveryService.class);
42 private static final int TIMEOUT = 15;
44 public EtherrainDiscoveryService() {
45 super(EtherRainBindingConstants.SUPPORTED_THING_TYPES_UIDS, TIMEOUT, true);
49 public Set<ThingTypeUID> getSupportedThingTypes() {
50 return EtherRainBindingConstants.SUPPORTED_THING_TYPES_UIDS;
54 protected void startScan() {
55 for (EtherRainUdpResponse rdp : EtherRainCommunication.autoDiscover()) {
57 ThingUID uid = new ThingUID(EtherRainBindingConstants.ETHERRAIN_THING,
58 rdp.getAddress().replaceAll("[^A-Za-z0-9\\-_]", ""));
59 DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(uid)
60 .withLabel("Etherrain " + rdp.getType() + " " + rdp.getUnqiueName())
61 .withProperty("host", rdp.getAddress()).withProperty("port", rdp.getPort()).build();
62 thingDiscovered(discoveryResult);
64 logger.debug("Nothing responded to request");