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.innogysmarthome.internal.discovery;
15 import static org.openhab.binding.innogysmarthome.internal.InnogyBindingConstants.THING_TYPE_BRIDGE;
17 import java.util.Collections;
20 import javax.jmdns.ServiceInfo;
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;
34 * The {@link InnogyBridgeDiscoveryParticipant} is responsible for discovering
35 * the innogy SmartHome bridge.
37 * @author Oliver Kuhl - Initial contribution
39 @Component(service = MDNSDiscoveryParticipant.class, configurationPid = "mdnsdiscovery.innogysmarthome")
41 public class InnogyBridgeDiscoveryParticipant implements MDNSDiscoveryParticipant {
43 private final Logger logger = LoggerFactory.getLogger(InnogyBridgeDiscoveryParticipant.class);
46 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
47 return Collections.singleton(THING_TYPE_BRIDGE);
51 public String getServiceType() {
52 return "_http._tcp.local.";
56 public @Nullable DiscoveryResult createResult(ServiceInfo service) {
57 ThingUID uid = getThingUID(service);
59 DiscoveryResult result = DiscoveryResultBuilder.create(uid)
60 .withLabel("innogy SmartHome Controller (" + service.getName() + ")").build();
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);