]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hdpowerview] Add support for setting repeater LED color and brightness (#12308)
authorJacob Laursen <jacob-github@vindvejr.dk>
Sat, 19 Feb 2022 20:48:38 +0000 (21:48 +0100)
committerGitHub <noreply@github.com>
Sat, 19 Feb 2022 20:48:38 +0000 (21:48 +0100)
* Add support for setting repeater LED color and brightness.

Fixes #12307

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
bundles/org.openhab.binding.hdpowerview/README.md
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewBindingConstants.java
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewWebTargets.java
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/Color.java [new file with mode: 0644]
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/RepeaterColor.java [new file with mode: 0644]
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/responses/RepeaterData.java
bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewRepeaterHandler.java
bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties
bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml

index 06547b6345af6aa1b44f8e010813ef62aab71808..d7ef2d2addd7ae2a8e5645b32820bc9ece8e5b53 100644 (file)
@@ -105,6 +105,8 @@ All of these channels appear in the binding, but only those which have a physica
 
 | Channel         | Item Type | Description                   |
 |-----------------|-----------|-------------------------------|
+| color           | Color     | Controls the color of the LED ring. A switch item can be linked: ON = white, OFF = turn off |
+| brightness      | Dimmer    | Controls the brightness of the LED ring. |
 | identify        | String    | Flash repeater to identify. Valid values are: `IDENTIFY` |
 | blinkingEnabled | Switch    | Blink during commands.        |
 
@@ -238,6 +240,8 @@ Number Living_Room_Shade_SignalStrength "Living Room Shade Signal Strength" {cha
 Repeater items:
 
 ```
+Color Bedroom_Repeater_Color "Bedroom Repeater Color" {channel="hdpowerview:repeater:home:r16384:color"}
+Dimmer Bedroom_Repeater_Brightness "Bedroom Repeater Brightness" {channel="hdpowerview:repeater:home:r16384:brightness"}
 String Bedroom_Repeater_Identify "Bedroom Repeater Identify" {channel="hdpowerview:repeater:home:r16384:identify"}
 Switch Bedroom_Repeater_BlinkingEnabled "Bedroom Repeater Blinking Enabled [%s]" {channel="hdpowerview:repeater:home:r16384:blinkingEnabled"}
 ```
@@ -272,6 +276,9 @@ Frame label="Living Room" {
     Text item=Living_Room_Shade_Battery_Voltage
 }
 Frame label="Bedroom" {
+    Colorpicker item=PowerViewRepeater_Color
+    Switch item=PowerViewRepeater_Color
+    Slider item=PowerViewRepeater_Brightness
     Switch item=Bedroom_Repeater_Identify mappings=[IDENTIFY="Identify"]
     Switch item=Bedroom_Repeater_BlinkingEnabled
 }
index b8800f394c1590163c37cd747d7a712215679040..1b19597dfa77097fa292f41ece429e4db1a22f3f 100644 (file)
@@ -47,6 +47,8 @@ public class HDPowerViewBindingConstants {
     public static final String CHANNEL_SHADE_BATTERY_VOLTAGE = "batteryVoltage";
     public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength";
 
+    public static final String CHANNEL_REPEATER_COLOR = "color";
+    public static final String CHANNEL_REPEATER_BRIGHTNESS = "brightness";
     public static final String CHANNEL_REPEATER_IDENTIFY = "identify";
     public static final String CHANNEL_REPEATER_BLINKING_ENABLED = "blinkingEnabled";
 
index aa7dd2f3ccc909221493562739bdc615a442dd5f..654e2f3c60bcfc57e2cde8fd28491d4f082267f0 100644 (file)
@@ -26,8 +26,10 @@ import org.eclipse.jetty.client.util.StringContentProvider;
 import org.eclipse.jetty.http.HttpHeader;
 import org.eclipse.jetty.http.HttpMethod;
 import org.eclipse.jetty.http.HttpStatus;
+import org.openhab.binding.hdpowerview.internal.api.Color;
 import org.openhab.binding.hdpowerview.internal.api.ShadePosition;
 import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterBlinking;
+import org.openhab.binding.hdpowerview.internal.api.requests.RepeaterColor;
 import org.openhab.binding.hdpowerview.internal.api.requests.ShadeCalibrate;
 import org.openhab.binding.hdpowerview.internal.api.requests.ShadeJog;
 import org.openhab.binding.hdpowerview.internal.api.requests.ShadeMove;
@@ -510,6 +512,22 @@ public class HDPowerViewWebTargets {
         return repeaterDataFromJson(jsonResponse);
     }
 
+    /**
+     * Sets color and brightness for a repeater
+     *
+     * @param repeaterId id of the repeater for which to set color and brightness
+     * @return RepeaterData class instance
+     * @throws HubInvalidResponseException if response is invalid
+     * @throws HubProcessingException if there is any processing error
+     * @throws HubMaintenanceException if the hub is down for maintenance
+     */
+    public RepeaterData setRepeaterColor(int repeaterId, Color color)
+            throws HubInvalidResponseException, HubProcessingException, HubMaintenanceException {
+        String jsonRequest = gson.toJson(new RepeaterColor(repeaterId, color));
+        String jsonResponse = invoke(HttpMethod.PUT, repeaters + repeaterId, null, jsonRequest);
+        return repeaterDataFromJson(jsonResponse);
+    }
+
     /**
      * Invoke a call on the hub server to retrieve information or send a command
      *
diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/Color.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/Color.java
new file mode 100644 (file)
index 0000000..39f1d0f
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2010-2022 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.hdpowerview.internal.api;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.core.library.types.HSBType;
+
+/**
+ * Color and brightness information for HD PowerView repeater
+ *
+ * @author Jacob Laursen - Initial contribution
+ */
+@NonNullByDefault
+public class Color {
+    public int brightness;
+    public int red;
+    public int green;
+    public int blue;
+
+    public Color(int brightness, HSBType hsbType) {
+        this.brightness = brightness;
+        int rgb = hsbType.getRGB();
+        java.awt.Color color = new java.awt.Color(rgb);
+        red = color.getRed();
+        green = color.getGreen();
+        blue = color.getBlue();
+    }
+
+    public Color(int brightness, java.awt.Color color) {
+        this.brightness = brightness;
+        red = color.getRed();
+        green = color.getGreen();
+        blue = color.getBlue();
+    }
+
+    public Color(int brightness, int red, int green, int blue) {
+        this.brightness = brightness;
+        this.red = red;
+        this.green = green;
+        this.blue = blue;
+    }
+
+    @Override
+    public String toString() {
+        return String.format("%d.%d.%d/%d%%", red, green, blue, brightness);
+    }
+}
diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/RepeaterColor.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/api/requests/RepeaterColor.java
new file mode 100644 (file)
index 0000000..960e95f
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2010-2022 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.hdpowerview.internal.api.requests;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.openhab.binding.hdpowerview.internal.api.Color;
+
+/**
+ * Color state of a single Repeater for being updated by an HD PowerView Hub
+ *
+ * @author Jacob Laursen - Initial contribution
+ */
+@NonNullByDefault
+public class RepeaterColor {
+    public Repeater repeater;
+
+    public class Repeater {
+        public int id;
+        public Color color;
+
+        public Repeater(int id, Color color) {
+            this.id = id;
+            this.color = color;
+        }
+    }
+
+    public RepeaterColor(int id, Color color) {
+        repeater = new Repeater(id, color);
+    }
+}
index 8b0c255309ec34f142199b393655b331981bc266..a083f91a35a76c5f9ba9424d32e05915859704aa 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Base64;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.hdpowerview.internal.api.Color;
 import org.openhab.binding.hdpowerview.internal.api.Firmware;
 
 /**
@@ -31,6 +32,7 @@ public class RepeaterData {
     public int groupId;
     public boolean blinkEnabled;
     public @Nullable Firmware firmware;
+    public @Nullable Color color;
 
     public String getName() {
         return new String(Base64.getDecoder().decode(name));
index 26b465ed99440137d1a209ef7abe788bb37ad2f8..1274ff1faa597c9bfbd1b1982919c4c9b02d6796 100644 (file)
@@ -20,13 +20,16 @@ import java.util.concurrent.TimeUnit;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.hdpowerview.internal.HDPowerViewWebTargets;
+import org.openhab.binding.hdpowerview.internal.api.Color;
 import org.openhab.binding.hdpowerview.internal.api.Firmware;
 import org.openhab.binding.hdpowerview.internal.api.responses.RepeaterData;
 import org.openhab.binding.hdpowerview.internal.config.HDPowerViewRepeaterConfiguration;
 import org.openhab.binding.hdpowerview.internal.exceptions.HubException;
 import org.openhab.binding.hdpowerview.internal.exceptions.HubInvalidResponseException;
 import org.openhab.binding.hdpowerview.internal.exceptions.HubMaintenanceException;
+import org.openhab.core.library.types.HSBType;
 import org.openhab.core.library.types.OnOffType;
+import org.openhab.core.library.types.PercentType;
 import org.openhab.core.library.types.StringType;
 import org.openhab.core.thing.Bridge;
 import org.openhab.core.thing.ChannelUID;
@@ -112,11 +115,43 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
             RepeaterData repeaterData;
 
             switch (channelUID.getId()) {
+                case CHANNEL_REPEATER_COLOR:
+                    if (command instanceof HSBType) {
+                        Color currentColor = webTargets.getRepeater(repeaterId).color;
+                        if (currentColor != null) {
+                            HSBType hsbCommand = (HSBType) command;
+                            var color = new Color(currentColor.brightness, hsbCommand);
+                            repeaterData = webTargets.setRepeaterColor(repeaterId, color);
+                            scheduler.submit(() -> updatePropertyAndStates(repeaterData));
+                        }
+                    } else if (command instanceof OnOffType) {
+                        Color currentColor = webTargets.getRepeater(repeaterId).color;
+                        if (currentColor != null) {
+                            var color = command == OnOffType.ON
+                                    ? new Color(currentColor.brightness, java.awt.Color.WHITE)
+                                    : new Color(currentColor.brightness, java.awt.Color.BLACK);
+                            repeaterData = webTargets.setRepeaterColor(repeaterId, color);
+                            scheduler.submit(() -> updatePropertyAndStates(repeaterData));
+                        }
+                    }
+                    break;
+                case CHANNEL_REPEATER_BRIGHTNESS:
+                    if (command instanceof PercentType) {
+                        Color currentColor = webTargets.getRepeater(repeaterId).color;
+                        if (currentColor != null) {
+                            PercentType brightness = (PercentType) command;
+                            var color = new Color(brightness.intValue(), currentColor.red, currentColor.green,
+                                    currentColor.blue);
+                            repeaterData = webTargets.setRepeaterColor(repeaterId, color);
+                            scheduler.submit(() -> updatePropertyAndStates(repeaterData));
+                        }
+                    }
+                    break;
                 case CHANNEL_REPEATER_IDENTIFY:
                     if (command instanceof StringType) {
                         if (COMMAND_IDENTIFY.equals(((StringType) command).toString())) {
                             repeaterData = webTargets.identifyRepeater(repeaterId);
-                            scheduler.submit(() -> updatePropertyAndState(repeaterData));
+                            scheduler.submit(() -> updatePropertyAndStates(repeaterData));
                             cancelResetIdentifyStateJob();
                             resetIdentifyStateFuture = scheduler.schedule(() -> {
                                 updateState(CHANNEL_REPEATER_IDENTIFY, UnDefType.UNDEF);
@@ -129,7 +164,7 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
                     break;
                 case CHANNEL_REPEATER_BLINKING_ENABLED:
                     repeaterData = webTargets.enableRepeaterBlinking(repeaterId, OnOffType.ON == command);
-                    scheduler.submit(() -> updatePropertyAndState(repeaterData));
+                    scheduler.submit(() -> updatePropertyAndStates(repeaterData));
                     break;
             }
         } catch (HubInvalidResponseException e) {
@@ -185,7 +220,7 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
             logger.debug("Polling for status information");
 
             RepeaterData repeaterData = webTargets.getRepeater(repeaterId);
-            updatePropertyAndState(repeaterData);
+            updatePropertyAndStates(repeaterData);
 
         } catch (HubInvalidResponseException e) {
             Throwable cause = e.getCause();
@@ -201,7 +236,7 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
         }
     }
 
-    private void updatePropertyAndState(RepeaterData repeaterData) {
+    private void updatePropertyAndStates(RepeaterData repeaterData) {
         updateStatus(ThingStatus.ONLINE);
 
         Firmware firmware = repeaterData.firmware;
@@ -212,6 +247,13 @@ public class HDPowerViewRepeaterHandler extends AbstractHubbedThingHandler {
             logger.warn("Repeater firmware version missing in response");
         }
 
+        Color color = repeaterData.color;
+        if (color != null) {
+            logger.debug("Repeater color data received: {}", color.toString());
+            updateState(CHANNEL_REPEATER_COLOR, HSBType.fromRGB(color.red, color.green, color.red));
+            updateState(CHANNEL_REPEATER_BRIGHTNESS, new PercentType(color.brightness));
+        }
+
         updateState(CHANNEL_REPEATER_BLINKING_ENABLED, repeaterData.blinkEnabled ? OnOffType.ON : OnOffType.OFF);
     }
 }
index d09d2fd988953518a26da670e0c4ea480ce19a8c..e72a760ba82085b77d1848363663a4723d73368e 100644 (file)
@@ -7,6 +7,8 @@ binding.hdpowerview.description = The Hunter Douglas PowerView binding provides
 
 thing-type.hdpowerview.hub.label = PowerView Hub
 thing-type.hdpowerview.hub.description = Hunter Douglas (Luxaflex) PowerView Hub
+thing-type.hdpowerview.repeater.channel.brightness.description = Controls the brightness of the LED ring
+thing-type.hdpowerview.repeater.channel.color.description = Controls the color of the LED ring
 thing-type.hdpowerview.repeater.label = PowerView Repeater
 thing-type.hdpowerview.repeater.description = Hunter Douglas (Luxaflex) PowerView Repeater
 thing-type.hdpowerview.shade.label = PowerView Shade
index a0c845f803a732a59602adfcd32f00e63f1a7522..95aaca7fc56d7d14dab508233a606a3b1bd736cc 100644 (file)
                <description>Hunter Douglas (Luxaflex) PowerView Repeater</description>
 
                <channels>
+                       <channel id="color" typeId="system.color">
+                               <description>Controls the color of the LED ring</description>
+                       </channel>
+                       <channel id="brightness" typeId="system.brightness">
+                               <description>Controls the brightness of the LED ring</description>
+                       </channel>
                        <channel id="identify" typeId="repeater-identify"/>
                        <channel id="blinkingEnabled" typeId="repeater-blinking-enabled"/>
                </channels>