]> git.basschouten.com Git - openhab-addons.git/commitdiff
[benqprojector] Add SDDP discovery and missing menu options (#16848)
authormlobstein <michael.lobstein@gmail.com>
Fri, 7 Jun 2024 16:45:16 +0000 (11:45 -0500)
committerGitHub <noreply@github.com>
Fri, 7 Jun 2024 16:45:16 +0000 (18:45 +0200)
* Add SDDP discovery

Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
bundles/org.openhab.binding.benqprojector/README.md
bundles/org.openhab.binding.benqprojector/src/main/feature/feature.xml
bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryParticipant.java [new file with mode: 0644]
bundles/org.openhab.binding.benqprojector/src/main/java/org/openhab/binding/benqprojector/internal/discovery/BenqProjectorDiscoveryService.java
bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/addon/addon.xml
bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/i18n/benqprojector.properties
bundles/org.openhab.binding.benqprojector/src/main/resources/OH-INF/thing/thing-types.xml

index 3598475c7f351dbbc41ddfa9f99b01a578da6132..d3917f455478cd39c8b7d9b3d6a3c30f4c801294 100644 (file)
@@ -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
 
index cc4133c31b19b8c44e5b1780e059a509b1bfc6f5..3da849f617f31feebdc076e16fec8694c3496ed3 100644 (file)
@@ -5,6 +5,7 @@
        <feature name="openhab-binding-benqprojector" description="BenQ 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.benqprojector/${project.version}</bundle>
        </feature>
 </features>
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 (file)
index 0000000..401b91c
--- /dev/null
@@ -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<ThingTypeUID> 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<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(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;
+    }
+}
index 8924ff0651a62cb6ee3419fd6d8b951167c031e3..dd80e4b5f496477db7da6154d81a69354495ed56 100644 (file)
@@ -78,7 +78,7 @@ public class BenqProjectorDiscoveryService extends AbstractDiscoveryService {
 
     @Override
     public Set<ThingTypeUID> getSupportedThingTypes() {
-        return SUPPORTED_THING_TYPES_UIDS;
+        return Set.of(THING_TYPE_PROJECTOR_TCP);
     }
 
     @Override
index 840de496efc31eb5b0f0055237880c3074866104..e341a0c6a81c7e18114496aa850e662e9e95a24e 100644 (file)
@@ -8,4 +8,20 @@
        <description>This binding is compatible with BenQ projectors</description>
        <connection>local</connection>
 
+       <discovery-methods>
+               <discovery-method>
+                       <service-type>sddp</service-type>
+                       <match-properties>
+                               <match-property>
+                                       <name>manufacturer</name>
+                                       <regex>(?i).*benq.*</regex>
+                               </match-property>
+                               <match-property>
+                                       <name>type</name>
+                                       <regex>(?i).*projector.*</regex>
+                               </match-property>
+                       </match-properties>
+               </discovery-method>
+       </discovery-methods>
+
 </addon:addon>
index 9644f6c228f48ef6da16238fe487d1c375ecc323..e2f5145b6f1c979567a596d484ba9b15def124f7 100644 (file)
@@ -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
index b8e99384f33aa6920b7b838f26803f0bba084c90..b2bc1219af989d76d5bf22ec5f7214e084c226cf 100644 (file)
@@ -79,6 +79,7 @@
                        <options>
                                <option value="hdmi">HDMI</option>
                                <option value="hdmi2">HDMI2</option>
+                               <option value="usbreader">USB Reader</option>
                                <option value="ypbr">Component</option>
                                <option value="rgb">Computer/YPbPr</option>
                                <option value="rgb2">Computer/YPbPr2</option>
@@ -97,6 +98,8 @@
                                <option value="preset">Presentation</option>
                                <option value="srgb">sRGB</option>
                                <option value="bright">Bright</option>
+                               <option value="brightcine">Bright Cinema</option>
+                               <option value="filmmaker">Filmmaker Mode</option>
                                <option value="livingroom">Living Room</option>
                                <option value="game">Game</option>
                                <option value="cine">Cinema</option>
                                <option value="isfday">ISF Day</option>
                                <option value="isfnight">ISF Night</option>
                                <option value="threed">3-D</option>
+                               <option value="hdr">HDR10</option>
+                               <option value="hdr+">HDR10+</option>
+                               <option value="hlg">HLG</option>
                        </options>
                </state>
        </channel-type>
                                <option value="auto">Auto</option>
                                <option value="lbox">Letterbox</option>
                                <option value="wide">Wide</option>
+                               <option value="2.35">2.35:1</option>
                        </options>
                </state>
        </channel-type>
        <channel-type id="lamptime">
                <item-type>Number</item-type>
                <label>Lamp Time</label>
-               <description>Retrieves the Lamp Hours</description>
+               <description>Retrieves the number of hours the lamp has been used</description>
                <state readOnly="true" pattern="%d h"/>
        </channel-type>