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.epsonprojector.internal.discovery;
15 import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.*;
17 import java.util.HashMap;
18 import java.util.Locale;
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.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;
37 * Discovery Service for Epson Projectors that support SDDP.
39 * @author Michael Lobstein - Initial contribution
43 @Component(immediate = true)
44 public class EpsonProjectorDiscoveryParticipant implements SddpDiscoveryParticipant {
45 private final Logger logger = LoggerFactory.getLogger(EpsonProjectorDiscoveryParticipant.class);
47 private static final String EPSON = "EPSON";
48 private static final String TYPE_PROJECTOR = "PROJECTOR";
51 public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
52 return SUPPORTED_THING_TYPES_UIDS;
56 public @Nullable DiscoveryResult createResult(SddpDevice device) {
57 final ThingUID uid = getThingUID(device);
59 final Map<String, Object> properties = new HashMap<>(3);
60 final String label = device.manufacturer + " " + device.model;
62 properties.put(Thing.PROPERTY_MAC_ADDRESS, uid.getId());
63 properties.put(THING_PROPERTY_HOST, device.ipAddress);
64 properties.put(THING_PROPERTY_PORT, DEFAULT_PORT);
66 final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
67 .withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).withLabel(label).build();
69 logger.debug("Created a DiscoveryResult for device '{}' with UID '{}'", label, uid.getId());
77 public @Nullable ThingUID getThingUID(SddpDevice device) {
78 if (device.manufacturer.toUpperCase(Locale.ENGLISH).contains(EPSON)
79 && device.type.toUpperCase(Locale.ENGLISH).contains(TYPE_PROJECTOR) && !device.macAddress.isBlank()) {
81 logger.debug("Epson projector with mac {} found at {}", device.macAddress, device.ipAddress);
82 return new ThingUID(THING_TYPE_PROJECTOR_TCP,
83 device.macAddress.replaceAll("-", "").toUpperCase(Locale.ENGLISH));