]> git.basschouten.com Git - openhab-addons.git/blob
d2f98740947fc1d23e16ca2853312fd8c3d63c07
[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.innogysmarthome.internal.discovery;
14
15 import static org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants.THING_TYPE_BRIDGE;
16
17 import java.util.Collections;
18 import java.util.Set;
19
20 import javax.jmdns.ServiceInfo;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.core.config.discovery.DiscoveryResult;
25 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
26 import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.ThingUID;
29 import org.osgi.service.component.annotations.Component;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 /**
34  * The {@link InnogyBridgeDiscoveryParticipant} is responsible for discovering
35  * the innogy SmartHome bridge.
36  *
37  * @author Oliver Kuhl - Initial contribution
38  */
39 @Component(service = MDNSDiscoveryParticipant.class, configurationPid = "mdnsdiscovery.innogysmarthome")
40 @NonNullByDefault
41 public class InnogyBridgeDiscoveryParticipant implements MDNSDiscoveryParticipant {
42
43     private final Logger logger = LoggerFactory.getLogger(InnogyBridgeDiscoveryParticipant.class);
44
45     @Override
46     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
47         return Collections.singleton(THING_TYPE_BRIDGE);
48     }
49
50     @Override
51     public String getServiceType() {
52         return "_http._tcp.local.";
53     }
54
55     @Override
56     public @Nullable DiscoveryResult createResult(ServiceInfo service) {
57         ThingUID uid = getThingUID(service);
58         if (uid != null) {
59             DiscoveryResult result = DiscoveryResultBuilder.create(uid)
60                     .withLabel("innogy SmartHome Controller (" + service.getName() + ")").build();
61             return result;
62         }
63         return null;
64     }
65
66     @Override
67     public @Nullable ThingUID getThingUID(@Nullable ServiceInfo service) {
68         if (service != null) {
69             String serviceName = service.getName();
70             if (serviceName.startsWith("SMARTHOME")) {
71                 logger.debug("Found innogy bridge via mDNS:{} v4:{} v6:{}", service.getName(),
72                         service.getInet4Addresses(), service.getInet6Addresses());
73                 return new ThingUID(THING_TYPE_BRIDGE, serviceName);
74             }
75         }
76         return null;
77     }
78 }