]> git.basschouten.com Git - openhab-addons.git/blob
294edd41cb550284438a7ad199f1baf6f3d06fa8
[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.vitotronic.internal.discovery;
14
15 import static org.openhab.binding.vitotronic.internal.VitotronicBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.vitotronic.internal.VitotronicBindingConstants;
19 import org.openhab.binding.vitotronic.internal.handler.VitotronicBridgeHandler;
20 import org.openhab.core.config.discovery.AbstractDiscoveryService;
21 import org.openhab.core.config.discovery.DiscoveryResult;
22 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
23 import org.openhab.core.thing.ThingUID;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * The {@link VitotronicBridgeDiscovery} class handles the discovery of things.
29  * with broadcasting and put it to inbox, if found.
30  *
31  *
32  * @author Stefan Andres - Initial contribution
33  */
34 @NonNullByDefault
35 public class VitotronicDiscoveryService extends AbstractDiscoveryService {
36
37     private final Logger logger = LoggerFactory.getLogger(VitotronicDiscoveryService.class);
38
39     private VitotronicBridgeHandler vitotronicBridgeHandler;
40
41     public VitotronicDiscoveryService(VitotronicBridgeHandler vitotronicBridgeHandler) throws IllegalArgumentException {
42         super(VitotronicBindingConstants.SUPPORTED_THING_TYPES_UIDS, 10, false);
43         this.vitotronicBridgeHandler = vitotronicBridgeHandler;
44     }
45
46     private void addThing(ThingUID bridgeUID, String thingType, String thingID) {
47         logger.trace("Adding new Vitotronic thing: {}", thingID);
48         ThingUID thingUID = null;
49         switch (thingType) {
50             case THING_ID_HEATING:
51                 thingUID = new ThingUID(THING_TYPE_UID_HEATING, bridgeUID, thingID);
52                 break;
53             case THING_ID_GASBURNER:
54                 thingUID = new ThingUID(THING_TYPE_UID_GASBURNER, bridgeUID, thingID);
55                 break;
56             case THING_ID_PELLETBURNER:
57                 thingUID = new ThingUID(THING_TYPE_UID_PELLETBURNER, bridgeUID, thingID);
58                 break;
59             case THING_ID_STORAGETANK:
60                 thingUID = new ThingUID(THING_TYPE_UID_STORAGETANK, bridgeUID, thingID);
61                 break;
62             case THING_ID_CIRCUIT:
63                 thingUID = new ThingUID(THING_TYPE_UID_CIRCUIT, bridgeUID, thingID);
64                 break;
65             case THING_ID_SOLAR:
66                 thingUID = new ThingUID(THING_TYPE_UID_SOLAR, bridgeUID, thingID);
67                 break;
68         }
69
70         if (thingUID != null) {
71             logger.trace("Adding new Discovery thingType: {} bridgeType: {}", thingUID, bridgeUID);
72             DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUID)
73                     .withLabel(thingID).build();
74             logger.trace("call register: {} label: {}", discoveryResult.getBindingId(), discoveryResult.getLabel());
75             thingDiscovered(discoveryResult);
76         } else {
77             logger.debug("Discovered Thing is unsupported: type '{}'", thingID);
78         }
79     }
80
81     public void addVitotronicThing(String thingType, String thingID) {
82         addThing(vitotronicBridgeHandler.getThing().getUID(), thingType, thingID);
83     }
84
85     public void activate() {
86         vitotronicBridgeHandler.registerDiscoveryService(this);
87     }
88
89     @Override
90     public void deactivate() {
91         vitotronicBridgeHandler.unregisterDiscoveryService();
92     }
93
94     @Override
95     protected void startScan() {
96         // Scan will be done by bridge
97     }
98 }