2 * Copyright (c) 2010-2021 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.amplipi.internal.discovery;
17 import javax.jmdns.ServiceInfo;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.amplipi.internal.AmpliPiBindingConstants;
22 import org.openhab.core.config.discovery.DiscoveryResult;
23 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
24 import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
29 * This is a discovery participant which finds AmpliPis on the local network
30 * through their mDNS announcements.
32 * @author Kai Kreuzer - Initial contribution
36 public class AmpliPiMDNSDiscoveryParticipant implements MDNSDiscoveryParticipant {
39 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
40 return Set.of(AmpliPiBindingConstants.THING_TYPE_CONTROLLER);
44 public String getServiceType() {
49 public @Nullable DiscoveryResult createResult(ServiceInfo service) {
50 ThingUID uid = getThingUID(service);
52 DiscoveryResult result = DiscoveryResultBuilder.create(uid).withLabel(service.getName())
53 .withProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME,
54 service.getInet4Addresses()[0].getHostAddress())
55 .withRepresentationProperty(AmpliPiBindingConstants.CFG_PARAM_HOSTNAME).build();
63 public @Nullable ThingUID getThingUID(ServiceInfo service) {
64 // TODO: Currently, the AmpliPi does not seem to announce any services.