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.qolsysiq.internal.discovery;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.qolsysiq.internal.QolsysIQBindingConstants;
20 import org.openhab.binding.qolsysiq.internal.handler.QolsysIQChildDiscoveryHandler;
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.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerService;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Simple discovery service that can be used by Partition and Zone Handlers
35 * @author Dan Cunningham - Initial contribution
39 public class QolsysIQChildDiscoveryService extends AbstractDiscoveryService
40 implements DiscoveryService, ThingHandlerService {
41 private final Logger logger = LoggerFactory.getLogger(QolsysIQChildDiscoveryService.class);
43 private static final Set<ThingTypeUID> SUPPORTED_DISCOVERY_THING_TYPES_UIDS = Set
44 .of(QolsysIQBindingConstants.THING_TYPE_PARTITION, QolsysIQBindingConstants.THING_TYPE_ZONE);
46 private @Nullable ThingHandler thingHandler;
48 public QolsysIQChildDiscoveryService() throws IllegalArgumentException {
49 super(SUPPORTED_DISCOVERY_THING_TYPES_UIDS, 5, false);
53 public void setThingHandler(ThingHandler handler) {
54 if (handler instanceof QolsysIQChildDiscoveryHandler childDiscoveryHandler) {
55 childDiscoveryHandler.setDiscoveryService(this);
56 this.thingHandler = handler;
61 public @Nullable ThingHandler getThingHandler() {
66 protected void startScan() {
67 ThingHandler handler = this.thingHandler;
68 if (handler != null) {
69 ((QolsysIQChildDiscoveryHandler) handler).startDiscovery();
74 public void activate() {
79 public void deactivate() {
83 public void discoverQolsysIQChildThing(ThingUID thingUID, ThingUID bridgeUID, Integer id, String label) {
84 logger.trace("discoverQolsysIQChildThing: {} {} {} {}", thingUID, bridgeUID, id, label);
85 DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withLabel(label).withProperty("id", id)
86 .withRepresentationProperty("id").withBridge(bridgeUID).build();
87 thingDiscovered(result);