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.bondhome.internal.discovery;
15 import static org.openhab.binding.bondhome.internal.BondHomeBindingConstants.*;
16 import static org.openhab.core.thing.Thing.*;
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 * This class identifies Bond Bridges by their mDNS service information.
36 * @author Sara Geleskie Damiano - Initial contribution
38 @Component(service = MDNSDiscoveryParticipant.class, configurationPid = "discovery.mdns.bondhome")
40 public class BondMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
42 private final Logger logger = LoggerFactory.getLogger(BondMDNSDiscoveryParticipant.class);
44 private static final String SERVICE_TYPE = "_bond._tcp.local.";
47 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
48 return SUPPORTED_BRIDGE_TYPES;
52 public String getServiceType() {
57 public @Nullable ThingUID getThingUID(@Nullable ServiceInfo service) {
58 if (service != null) {
59 return new ThingUID(THING_TYPE_BOND_BRIDGE, service.getName());
65 public @Nullable DiscoveryResult createResult(ServiceInfo service) {
66 ThingUID thingUID = getThingUID(service);
67 if (thingUID != null) {
68 logger.debug("Discovered Bond Bridge: {}", service);
69 return DiscoveryResultBuilder.create(thingUID).withProperty(PROPERTY_SERIAL_NUMBER, service.getName())
70 .withLabel("@text/discovery.bridge.label").withRepresentationProperty(PROPERTY_SERIAL_NUMBER)