2 * Copyright (c) 2010-2024 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.sonyprojector.internal.discovery;
15 import static org.openhab.binding.sonyprojector.internal.SonyProjectorBindingConstants.THING_TYPE_ETHERNET;
17 import java.util.Locale;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.sonyprojector.internal.configuration.SonyProjectorEthernetConfiguration;
24 import org.openhab.core.config.discovery.DiscoveryResult;
25 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
26 import org.openhab.core.config.discovery.sddp.SddpDevice;
27 import org.openhab.core.config.discovery.sddp.SddpDiscoveryParticipant;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.ThingUID;
31 import org.osgi.service.component.annotations.Component;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Discovery Service for Sony Projectors that support SDDP.
38 * @author Laurent Garnier - Initial contribution
42 @Component(immediate = true)
43 public class SonyProjectorDiscoveryParticipant implements SddpDiscoveryParticipant {
44 private final Logger logger = LoggerFactory.getLogger(SonyProjectorDiscoveryParticipant.class);
46 private static final String SONY = "SONY";
47 private static final String TYPE_PROJECTOR = "PROJECTOR";
50 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
51 return Set.of(THING_TYPE_ETHERNET);
55 public @Nullable DiscoveryResult createResult(SddpDevice device) {
56 final ThingUID uid = getThingUID(device);
58 final String label = device.manufacturer + " " + device.model;
59 final Map<String, Object> properties = Map.of("host", device.ipAddress, //
60 "port", SonyProjectorEthernetConfiguration.DEFAULT_PORT, //
61 "model", SonyProjectorEthernetConfiguration.MODEL_AUTO, //
62 Thing.PROPERTY_MAC_ADDRESS, device.macAddress);
63 logger.debug("Created a DiscoveryResult for device '{}' with UID '{}'", label, uid.getId());
64 return DiscoveryResultBuilder.create(uid).withProperties(properties)
65 .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).withLabel(label).build();
72 public @Nullable ThingUID getThingUID(SddpDevice device) {
73 if (device.manufacturer.toUpperCase(Locale.ENGLISH).contains(SONY)
74 && device.type.toUpperCase(Locale.ENGLISH).contains(TYPE_PROJECTOR) && !device.macAddress.isBlank()
75 && !device.ipAddress.isBlank()) {
77 logger.debug("Sony projector with mac {} found at {}", device.macAddress, device.ipAddress);
78 return new ThingUID(THING_TYPE_ETHERNET, device.macAddress);