]> git.basschouten.com Git - openhab-addons.git/blob
6dd716e46dedb7504bea74ec09d46a61a13d5196
[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.coronastats.internal.discovery;
14
15 import static org.openhab.binding.coronastats.internal.CoronaStatsBindingConstants.*;
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 CoronaStatsDiscoveryService} create a default world thing.
29  *
30  * @author Johannes Ott - Initial contribution
31  */
32 @NonNullByDefault
33 @Component(service = DiscoveryService.class, configurationPid = "discovery.coronastats")
34 public class CoronaStatsDiscoveryService extends AbstractDiscoveryService {
35     private static final ThingUID WORLD_THING_UID = new ThingUID(THING_TYPE_WORLD, STATS);
36     private static final int DISCOVER_TIMEOUT_SECONDS = 2;
37
38     private final Logger logger = LoggerFactory.getLogger(CoronaStatsDiscoveryService.class);
39
40     public CoronaStatsDiscoveryService() throws IllegalArgumentException {
41         super(SUPPORTED_THING_TYPES_UIDS, DISCOVER_TIMEOUT_SECONDS, true);
42     }
43
44     @Override
45     protected void startScan() {
46         logger.debug("Manual CoronaStats discovery scan.");
47         addWorld();
48     }
49
50     @Override
51     protected void startBackgroundDiscovery() {
52         logger.debug("Background CoronaStats discovery scan.");
53         addWorld();
54     }
55
56     private void addWorld() {
57         // @formatter:off
58         DiscoveryResult world = DiscoveryResultBuilder
59             .create(WORLD_THING_UID)
60             .withLabel(WORLD_LABEL)
61             .build();
62         // @formatter:on
63
64         thingDiscovered(world);
65     }
66 }