[epsonprojector] Add SDDP discovery (#16802)

* Replace AMX discovery with SDDP

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
mlobstein 2024-06-05 01:04:35 -05:00 committed by Ciprian Pascu
parent 1789d545cd
commit dc780ac4b1
3 changed files with 119 additions and 31 deletions

View File

@ -9,7 +9,7 @@ This binding supports two thing types based on the connection used: `projector-s
## Discovery
If the projector has a built-in Ethernet port connected to the same network as the openHAB server and the 'AMX Device Discovery' option is present and enabled in the projector's network menu, the thing will be discovered automatically.
If the projector has a built-in Ethernet port connected to the same network as the openHAB server and either the 'AMX Device Discovery' or 'Control4 SDDP' options are present and enabled in the projector's network menu, the thing will be discovered automatically.
Serial port or serial over IP connections must be configured manually.
## Binding Configuration
@ -72,36 +72,36 @@ connection: &conEpson
## Channels
| Channel | Item Type | Purpose | Values |
| ------------------ | --------- | ------------------------------------------------------------------------------------------ | --------- |
| power | Switch | Powers the projector on or off. | |
| powerstate | String | Retrieves the textual power state of the projector. | Read only |
| source | String | Retrieve or set the input source. | See above |
| aspectratio | String | Retrieve or set the aspect ratio. | See above |
| colormode | String | Retrieve or set the color mode. | See above |
| freeze | Switch | Turn the freeze screen mode on or off. | |
| mute | Switch | Turn the AV mute on or off. | |
| volume | Dimmer | Retrieve or set the volume. Scaled to 0-20 or 0-40 on the projector per maxVolume setting. | 0% - 100% |
| luminance | String | Retrieve or set the lamp mode. | See above |
| brightness | Number | Retrieve or set the brightness. | -24 - +24 |
| contrast | Number | Retrieve or set the contrast. | -24 - +24 |
| density | Number | Retrieve or set the density (color saturation). | -32 - +32 |
| tint | Number | Retrieve or set the tint. | -32 - +32 |
| colortemperature | Number | Retrieve or set the color temperature. | 0 - +9 |
| fleshtemperature | Number | Retrieve or set the flesh temperature. | 0 - +6 |
| gamma | String | Retrieve or set the gamma setting. | See above |
| autokeystone | Switch | Turn the auto keystone mode on or off. | |
| verticalkeystone | Number | Retrieve or set the vertical keystone. | -30 - +30 |
| horizontalkeystone | Number | Retrieve or set the horizontal keystone. | -30 - +30 |
| verticalposition | Number | Retrieve or set the vertical position. | -8 - +10 |
| horizontalposition | Number | Retrieve or set the horizontal position. | -23 - +26 |
| verticalreverse | Switch | Turn the vertical reverse mode on or off. | |
| horizontalreverse | Switch | Turn the horizontal reverse mode on or off. | |
| background | String | Retrieve or set the background color/logo. | See above |
| keycode | String | Send a key operation command to the projector. (2 character code) | Send only |
| lamptime | Number | Retrieves the lamp hours. | Read only |
| errcode | Number | Retrieves the last error code. | Read only |
| errmessage | String | Retrieves the description of the last error. | Read only |
| Channel | Item Type | Purpose | Values |
| ------------------ | --------- | ------------------------------------------------------------------------------------------ | ---------- |
| power | Switch | Powers the projector on or off. | |
| powerstate | String | Retrieves the textual power state of the projector. | Read only |
| source | String | Retrieve or set the input source. | See above |
| aspectratio | String | Retrieve or set the aspect ratio. | See above |
| colormode | String | Retrieve or set the color mode. | See above |
| freeze | Switch | Turn the freeze screen mode on or off. | |
| mute | Switch | Turn the AV mute on or off. | |
| volume | Dimmer | Retrieve or set the volume. Scaled to 0-20 or 0-40 on the projector per maxVolume setting. | 0% - 100% |
| luminance | String | Retrieve or set the lamp mode. | See above |
| brightness | Number | Retrieve or set the brightness. | -24 - +24 |
| contrast | Number | Retrieve or set the contrast. | -24 - +24 |
| density | Number | Retrieve or set the density (color saturation). | -32 - +32 |
| tint | Number | Retrieve or set the tint. | -32 - +32 |
| colortemperature | Number | Retrieve or set the color temperature. | 0 - +9 |
| fleshtemperature | Number | Retrieve or set the flesh temperature. | 0 - +6 |
| gamma | String | Retrieve or set the gamma setting. | See above |
| autokeystone | Switch | Turn the auto keystone mode on or off. | |
| verticalkeystone | Number | Retrieve or set the vertical keystone. | -30 - +30 |
| horizontalkeystone | Number | Retrieve or set the horizontal keystone. | -30 - +30 |
| verticalposition | Number | Retrieve or set the vertical position. | -8 - +10 |
| horizontalposition | Number | Retrieve or set the horizontal position. | -23 - +26 |
| verticalreverse | Switch | Turn the vertical reverse mode on or off. | |
| horizontalreverse | Switch | Turn the horizontal reverse mode on or off. | |
| background | String | Retrieve or set the background color/logo. | See above |
| keycode | String | Send a key operation command to the projector. (2 character code) | Write only |
| lamptime | Number | Retrieves the number of hours the lamp has been used. | Read only |
| errcode | Number | Retrieves the last error code. | Read only |
| errmessage | String | Retrieves the description of the last error. | Read only |
## Full Example

View File

@ -5,6 +5,7 @@
<feature name="openhab-binding-epsonprojector" description="Epson Projector Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<feature>openhab-transport-serial</feature>
<feature>openhab-core-config-discovery-sddp</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.epsonprojector/${project.version}</bundle>
</feature>
</features>

View File

@ -0,0 +1,87 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.epsonprojector.internal.discovery;
import static org.openhab.binding.epsonprojector.internal.EpsonProjectorBindingConstants.*;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.sddp.SddpDevice;
import org.openhab.core.config.discovery.sddp.SddpDiscoveryParticipant;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* Discovery Service for Epson Projectors that support SDDP.
*
* @author Michael Lobstein - Initial contribution
*
*/
@NonNullByDefault
@Component(immediate = true)
public class EpsonProjectorDiscoveryParticipant implements SddpDiscoveryParticipant {
private final Logger logger = LoggerFactory.getLogger(EpsonProjectorDiscoveryParticipant.class);
private static final String EPSON = "EPSON";
private static final String TYPE_PROJECTOR = "PROJECTOR";
@Override
public Set<ThingTypeUID> getSupportedThingTypeUIDs() {
return SUPPORTED_THING_TYPES_UIDS;
}
@Override
public @Nullable DiscoveryResult createResult(SddpDevice device) {
final ThingUID uid = getThingUID(device);
if (uid != null) {
final Map<String, Object> properties = new HashMap<>(3);
final String label = device.manufacturer + " " + device.model;
properties.put(Thing.PROPERTY_MAC_ADDRESS, uid.getId());
properties.put(THING_PROPERTY_HOST, device.ipAddress);
properties.put(THING_PROPERTY_PORT, DEFAULT_PORT);
final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties)
.withRepresentationProperty(Thing.PROPERTY_MAC_ADDRESS).withLabel(label).build();
logger.debug("Created a DiscoveryResult for device '{}' with UID '{}'", label, uid.getId());
return result;
} else {
return null;
}
}
@Override
public @Nullable ThingUID getThingUID(SddpDevice device) {
if (device.manufacturer.toUpperCase(Locale.ENGLISH).contains(EPSON)
&& device.type.toUpperCase(Locale.ENGLISH).contains(TYPE_PROJECTOR) && !device.macAddress.isBlank()) {
logger.debug("Epson projector with mac {} found at {}", device.macAddress, device.ipAddress);
return new ThingUID(THING_TYPE_PROJECTOR_TCP,
device.macAddress.replaceAll("-", "").toUpperCase(Locale.ENGLISH));
}
return null;
}
}