]> git.basschouten.com Git - openhab-addons.git/blob
9a6b7e76183ff74f3fbbe7c84ed09f52369b66dd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.dwdpollenflug.internal.discovery;
14
15 import static org.openhab.binding.dwdpollenflug.internal.DWDPollenflugBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.config.discovery.AbstractDiscoveryService;
19 import org.openhab.core.config.discovery.DiscoveryResult;
20 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
21 import org.openhab.core.config.discovery.DiscoveryService;
22 import org.openhab.core.thing.ThingUID;
23 import org.osgi.service.component.annotations.Component;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {@link DWDPollenflugDiscoveryService} create a default bridge thing.
29  *
30  * @author Johannes Ott - Initial contribution
31  */
32 @NonNullByDefault
33 @Component(service = DiscoveryService.class, configurationPid = "discovery.dwdpollenflug")
34 public class DWDPollenflugDiscoveryService extends AbstractDiscoveryService {
35     private static final ThingUID BRIDGE_THING_UID = new ThingUID(THING_TYPE_BRIDGE, DWD);
36     private static final int DISCOVER_TIMEOUT_SECONDS = 2;
37
38     private final Logger logger = LoggerFactory.getLogger(DWDPollenflugDiscoveryService.class);
39
40     public DWDPollenflugDiscoveryService() throws IllegalArgumentException {
41         super(SUPPORTED_THING_TYPES_UIDS, DISCOVER_TIMEOUT_SECONDS, true);
42     }
43
44     @Override
45     protected void startScan() {
46         logger.debug("Manual DWDPollenflug discovery scan.");
47         addBridge();
48     }
49
50     @Override
51     protected void startBackgroundDiscovery() {
52         logger.debug("Background DWDPollenflug discovery scan.");
53         addBridge();
54     }
55
56     private void addBridge() {
57         // @formatter:off
58         DiscoveryResult bridge = DiscoveryResultBuilder
59             .create(BRIDGE_THING_UID)
60             .withLabel(BRIDGE_LABEL)
61             .build();
62         // @formatter:on
63
64         thingDiscovered(bridge);
65     }
66 }