From 614b42d2a4251995c2e50166c5571644742803f0 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Fri, 7 Jun 2024 11:45:16 -0500 Subject: [PATCH] [benqprojector] Add SDDP discovery and missing menu options (#16848) * Add SDDP discovery Signed-off-by: Michael Lobstein --- .../README.md | 22 ++--- .../src/main/feature/feature.xml | 1 + .../BenqProjectorDiscoveryParticipant.java | 88 +++++++++++++++++++ .../BenqProjectorDiscoveryService.java | 2 +- .../src/main/resources/OH-INF/addon/addon.xml | 16 ++++ .../OH-INF/i18n/benqprojector.properties | 9 +- .../resources/OH-INF/thing/thing-types.xml | 9 +- 7 files changed, 133 insertions(+), 14 deletions(-) create mode 100644 bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryParticipant.java diff --git a/bundles/org.openhab.binding.benqprojector/README.md b/bundles/org.openhab.binding.benqprojector/README.md index 3598475c7f3..d3917f45547 100644 --- a/bundles/org.openhab.binding.benqprojector/README.md +++ b/bundles/org.openhab.binding.benqprojector/README.md @@ -11,7 +11,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 supports AMX Device Discovery, 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' 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 @@ -55,16 +55,16 @@ Some notes: ## Channels -| Channel | Item Type | Purpose | Values | -| ------------------ | --------- | --------------------------------------------------- | --------- | -| power | Switch | Powers the projector on or off. | | -| source | String | Retrieve or set the input source. | See above | -| picturemode | String | Retrieve or set the picture mode. | See above | -| aspectratio | String | Retrieve or set the aspect ratio. | See above | -| freeze | Switch | Turn the freeze image mode on or off. | | -| blank | Switch | Turn the screen blank mode on or off. | | -| directcmd | String | Send a command directly to the projector. | Send only | -| lamptime | Number | Retrieves the lamp hours. | Read only | +| Channel | Item Type | Purpose | Values | +| ------------------ | --------- | ----------------------------------------------------- | ---------- | +| power | Switch | Powers the projector on or off. | | +| source | String | Retrieve or set the input source. | See above | +| picturemode | String | Retrieve or set the picture mode. | See above | +| aspectratio | String | Retrieve or set the aspect ratio. | See above | +| freeze | Switch | Turn the freeze image mode on or off. | | +| blank | Switch | Turn the screen blank mode on or off. | | +| directcmd | String | Send a command directly to the projector. | Write only | +| lamptime | Number | Retrieves the number of hours the lamp has been used. | Read only | ## Full Example diff --git a/bundles/org.openhab.binding.benqprojector/src/main/feature/feature.xml b/bundles/org.openhab.binding.benqprojector/src/main/feature/feature.xml index cc4133c31b1..3da849f617f 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/feature/feature.xml +++ b/bundles/org.openhab.binding.benqprojector/src/main/feature/feature.xml @@ -5,6 +5,7 @@ openhab-runtime-base openhab-transport-serial + openhab-core-config-discovery-sddp mvn:org.openhab.addons.bundles/org.openhab.binding.benqprojector/${project.version} diff --git a/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryParticipant.java b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryParticipant.java new file mode 100644 index 00000000000..401b91c79b7 --- /dev/null +++ b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryParticipant.java @@ -0,0 +1,88 @@ +/** + * 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.benqprojector.internal.discovery; + +import static org.openhab.binding.benqprojector.internal.BenqProjectorBindingConstants.*; + +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 BenQ Projectors that support SDDP. + * + * @author Michael Lobstein - Initial contribution + * + */ +@NonNullByDefault +@Component(immediate = true) +public class BenqProjectorDiscoveryParticipant implements SddpDiscoveryParticipant { + private final Logger logger = LoggerFactory.getLogger(BenqProjectorDiscoveryParticipant.class); + + private static final String BENQ = "BENQ"; + private static final String TYPE_PROJECTOR = "PROJECTOR"; + + @Override + public Set getSupportedThingTypeUIDs() { + return Set.of(THING_TYPE_PROJECTOR_TCP); + } + + @Override + public @Nullable DiscoveryResult createResult(SddpDevice device) { + final ThingUID uid = getThingUID(device); + if (uid != null) { + final Map 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(BENQ) + && device.type.toUpperCase(Locale.ENGLISH).contains(TYPE_PROJECTOR) && !device.macAddress.isBlank() + && !device.ipAddress.isBlank()) { + logger.debug("BenQ projector with mac {} found at {}", device.macAddress, device.ipAddress); + + return new ThingUID(THING_TYPE_PROJECTOR_TCP, + device.macAddress.replaceAll("-", "").toUpperCase(Locale.ENGLISH)); + } + return null; + } +} diff --git a/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryService.java b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryService.java index 8924ff0651a..dd80e4b5f49 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryService.java +++ b/bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryService.java @@ -78,7 +78,7 @@ public class BenqProjectorDiscoveryService extends AbstractDiscoveryService { @Override public Set getSupportedThingTypes() { - return SUPPORTED_THING_TYPES_UIDS; + return Set.of(THING_TYPE_PROJECTOR_TCP); } @Override diff --git a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/addon/addon.xml b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/addon/addon.xml index 840de496efc..e341a0c6a81 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/addon/addon.xml +++ b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/addon/addon.xml @@ -8,4 +8,20 @@ This binding is compatible with BenQ projectors local + + + sddp + + + manufacturer + (?i).*benq.* + + + type + (?i).*projector.* + + + + + diff --git a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/i18n/benqprojector.properties b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/i18n/benqprojector.properties index 9644f6c228f..e2f5145b6f1 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/i18n/benqprojector.properties +++ b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/i18n/benqprojector.properties @@ -33,6 +33,7 @@ channel-type.benqprojector.aspectratio.state.option.16:9 = 16:9 channel-type.benqprojector.aspectratio.state.option.auto = Auto channel-type.benqprojector.aspectratio.state.option.lbox = Letterbox channel-type.benqprojector.aspectratio.state.option.wide = Wide +channel-type.benqprojector.aspectratio.state.option.2.35 = 2.35:1 channel-type.benqprojector.blank.label = Screen Blank channel-type.benqprojector.blank.description = Turn the Screen Blank On or Off channel-type.benqprojector.directcmd.label = Direct Command @@ -54,13 +55,15 @@ channel-type.benqprojector.directcmd.state.option.enter = Enter channel-type.benqprojector.freeze.label = Freeze Image channel-type.benqprojector.freeze.description = Turn the Freeze Image Mode On or Off channel-type.benqprojector.lamptime.label = Lamp Time -channel-type.benqprojector.lamptime.description = Retrieves the Lamp Hours +channel-type.benqprojector.lamptime.description = Retrieves the number of hours the lamp has been used channel-type.benqprojector.picturemode.label = Picture Mode channel-type.benqprojector.picturemode.description = Retrieve or Set the Picture Mode channel-type.benqprojector.picturemode.state.option.dynamic = Dynamic channel-type.benqprojector.picturemode.state.option.preset = Presentation channel-type.benqprojector.picturemode.state.option.srgb = sRGB channel-type.benqprojector.picturemode.state.option.bright = Bright +channel-type.benqprojector.picturemode.state.option.brightcine = Bright Cinema +channel-type.benqprojector.picturemode.state.option.filmmaker = Filmmaker Mode channel-type.benqprojector.picturemode.state.option.livingroom = Living Room channel-type.benqprojector.picturemode.state.option.game = Game channel-type.benqprojector.picturemode.state.option.cine = Cinema @@ -73,10 +76,14 @@ channel-type.benqprojector.picturemode.state.option.user3 = User 3 channel-type.benqprojector.picturemode.state.option.isfday = ISF Day channel-type.benqprojector.picturemode.state.option.isfnight = ISF Night channel-type.benqprojector.picturemode.state.option.threed = 3-D +channel-type.benqprojector.picturemode.state.option.hdr = HDR10 +channel-type.benqprojector.picturemode.state.option.hdr+ = HDR10+ +channel-type.benqprojector.picturemode.state.option.hlg = HLG channel-type.benqprojector.source.label = Source channel-type.benqprojector.source.description = Retrieve or Set the Input Source channel-type.benqprojector.source.state.option.hdmi = HDMI channel-type.benqprojector.source.state.option.hdmi2 = HDMI2 +channel-type.benqprojector.source.state.option.usbreader = USB Reader channel-type.benqprojector.source.state.option.ypbr = Component channel-type.benqprojector.source.state.option.rgb = Computer/YPbPr channel-type.benqprojector.source.state.option.rgb2 = Computer/YPbPr2 diff --git a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/thing/thing-types.xml index b8e99384f33..b2bc1219af9 100644 --- a/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/thing/thing-types.xml @@ -79,6 +79,7 @@ + @@ -97,6 +98,8 @@ + + @@ -109,6 +112,9 @@ + + + @@ -123,6 +129,7 @@ + @@ -162,7 +169,7 @@ Number - Retrieves the Lamp Hours + Retrieves the number of hours the lamp has been used