]> git.basschouten.com Git - openhab-addons.git/blob
e64f8a74ef50248ca578982b85b11f17b795f4b3
[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.bondhome.internal.discovery;
14
15 import static org.openhab.binding.bondhome.internal.BondHomeBindingConstants.*;
16 import static org.openhab.core.thing.Thing.*;
17
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  * This class identifies Bond Bridges by their mDNS service information.
35  *
36  * @author Sara Geleskie Damiano - Initial contribution
37  */
38 @Component(service = MDNSDiscoveryParticipant.class, configurationPid = "discovery.mdns.bondhome")
39 @NonNullByDefault
40 public class BondMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
41
42     private final Logger logger = LoggerFactory.getLogger(BondMDNSDiscoveryParticipant.class);
43
44     private static final String SERVICE_TYPE = "_bond._tcp.local.";
45
46     @Override
47     public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
48         return SUPPORTED_BRIDGE_TYPES;
49     }
50
51     @Override
52     public String getServiceType() {
53         return SERVICE_TYPE;
54     }
55
56     @Override
57     public @Nullable ThingUID getThingUID(@Nullable ServiceInfo service) {
58         if (service != null) {
59             return new ThingUID(THING_TYPE_BOND_BRIDGE, service.getName());
60         }
61         return null;
62     }
63
64     @Override
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)
71                     .build();
72         }
73         return null;
74     }
75 }