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.electroluxair.internal.discovery;
15 import static org.openhab.binding.electroluxair.internal.ElectroluxAirBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.electroluxair.internal.ElectroluxAirConfiguration;
22 import org.openhab.binding.electroluxair.internal.handler.ElectroluxAirBridgeHandler;
23 import org.openhab.core.config.discovery.AbstractDiscoveryService;
24 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
25 import org.openhab.core.config.discovery.DiscoveryService;
26 import org.openhab.core.thing.ThingUID;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerService;
31 * The {@link ElectroluxAirDiscoveryService} searches for available
32 * Electrolux Pure A9 discoverable through Electrolux Delta API.
34 * @author Jan Gustafsson - Initial contribution
37 public class ElectroluxAirDiscoveryService extends AbstractDiscoveryService
38 implements ThingHandlerService, DiscoveryService {
39 private static final int SEARCH_TIME = 2;
40 private @Nullable ElectroluxAirBridgeHandler handler;
42 public ElectroluxAirDiscoveryService() {
43 super(SUPPORTED_THING_TYPES_UIDS, SEARCH_TIME);
47 public void setThingHandler(@Nullable ThingHandler handler) {
48 if (handler instanceof ElectroluxAirBridgeHandler) {
49 this.handler = (ElectroluxAirBridgeHandler) handler;
54 public @Nullable ThingHandler getThingHandler() {
59 public void activate(@Nullable Map<String, Object> configProperties) {
60 super.activate(configProperties);
64 public void deactivate() {
69 protected void startScan() {
70 ElectroluxAirBridgeHandler bridgeHandler = this.handler;
71 if (bridgeHandler != null) {
72 ThingUID bridgeUID = bridgeHandler.getThing().getUID();
73 bridgeHandler.getElectroluxAirThings().entrySet().stream().forEach(thing -> {
74 thingDiscovered(DiscoveryResultBuilder
75 .create(new ThingUID(THING_TYPE_ELECTROLUX_PURE_A9, bridgeUID, thing.getKey()))
76 .withLabel("Electrolux Pure A9").withBridge(bridgeUID)
77 .withProperty(ElectroluxAirConfiguration.DEVICE_ID_LABEL, thing.getKey())
78 .withRepresentationProperty(ElectroluxAirConfiguration.DEVICE_ID_LABEL).build());