]> git.basschouten.com Git - openhab-addons.git/blob
c875c066d08537c23468fb47e2f08e8d9bf0c7cb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.electroluxair.internal.discovery;
14
15 import static org.openhab.binding.electroluxair.internal.ElectroluxAirBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.electroluxair.internal.ElectroluxAirConfiguration;
19 import org.openhab.binding.electroluxair.internal.handler.ElectroluxAirBridgeHandler;
20 import org.openhab.core.config.discovery.AbstractThingHandlerDiscoveryService;
21 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
22 import org.openhab.core.thing.ThingUID;
23 import org.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.ServiceScope;
25
26 /**
27  * The {@link ElectroluxAirDiscoveryService} searches for available
28  * Electrolux Pure A9 discoverable through Electrolux Delta API.
29  *
30  * @author Jan Gustafsson - Initial contribution
31  */
32 @Component(scope = ServiceScope.PROTOTYPE, service = ElectroluxAirDiscoveryService.class)
33 @NonNullByDefault
34 public class ElectroluxAirDiscoveryService extends AbstractThingHandlerDiscoveryService<ElectroluxAirBridgeHandler> {
35     private static final int SEARCH_TIME = 2;
36
37     public ElectroluxAirDiscoveryService() {
38         super(ElectroluxAirBridgeHandler.class, SUPPORTED_THING_TYPES_UIDS, SEARCH_TIME);
39     }
40
41     @Override
42     protected void startScan() {
43         ThingUID bridgeUID = thingHandler.getThing().getUID();
44         thingHandler.getElectroluxAirThings().entrySet().stream().forEach(thing -> {
45             thingDiscovered(DiscoveryResultBuilder
46                     .create(new ThingUID(THING_TYPE_ELECTROLUX_PURE_A9, bridgeUID, thing.getKey()))
47                     .withLabel("Electrolux Pure A9").withBridge(bridgeUID)
48                     .withProperty(ElectroluxAirConfiguration.DEVICE_ID_LABEL, thing.getKey())
49                     .withRepresentationProperty(ElectroluxAirConfiguration.DEVICE_ID_LABEL).build());
50         });
51
52         stopScan();
53     }
54 }