]> git.basschouten.com Git - openhab-addons.git/commitdiff
[hdpowerview] Add new battery level channel (#11206)
authorjlaur <jacob-github@vindvejr.dk>
Wed, 8 Sep 2021 18:36:59 +0000 (20:36 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Sep 2021 18:36:59 +0000 (20:36 +0200)
* Introduce new batteryLevel channel.

Fixes #11205

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/handler/HDPowerViewShadeHandler.java
bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/thing-types.xml
bundles/org.openhab.binding.hdpowerview/src/test/java/org/openhab/binding/hdpowerview/HDPowerViewJUnitTests.java
bundles/org.openhab.binding.hdpowerview/src/test/resources/duette.json

index ab9fe8f76f07e6be5c30b499a40e4ef6b6a632f6..7f043983b74f6a36a146576a45e98d4a1a84a366 100644 (file)
@@ -74,11 +74,12 @@ If it is a dual action (top-down plus bottom-up) shade, there is also a roller s
 All of these channels appear in the binding, but only those which have a physical implementation in the shade, will have any physical effect.
 
 | Channel        | Item Type                | Description |
-|----------------|--------------------------|------------|
+|----------------|--------------------------|-------------|
 | position       | Rollershutter            | The vertical position of the shade's rail -- see [next chapter](#Roller-Shutter-Up/Down-Position-vs.-Open/Close-State). Up/Down commands will move the rail completely up or completely down. Percentage commands will move the rail to an intermediate position. Stop commands will halt any current movement of the rail. |
 | secondary      | Rollershutter            | The vertical position of the secondary rail (if any). Its function is basically identical to the `position` channel above -- but see [next chapter](#Roller-Shutter-Up/Down-Position-vs.-Open/Close-State). |
 | vane           | Dimmer                   | The degree of opening of the slats or vanes. Setting this to a non-zero value will first move the shade `position` fully down, since the slats or vanes can only have a defined state if the shade is in its down position -- see [Interdependency between Channel positions](#Interdependency-between-Channel-positions). |
 | lowBattery     | Switch                   | Indicates ON when the battery level of the shade is low, as determined by the hub's internal rules. |
+| batteryLevel   | Number                   | Battery level (10% = low, 50% = medium, 100% = high)
 | batteryVoltage | Number:ElectricPotential | Battery voltage reported by the shade. |
 | signalStrength | Number                   | Signal strength (0 for no or unknown signal, 1 for weak, 2 for average, 3 for good or 4 for excellent) |
 
index 1b710cb277a716aeee83690b46aa1e960b160e24..da235dd22c8dafa5b10e450ffc1c98eeddc1db6c 100644 (file)
@@ -41,6 +41,7 @@ public class HDPowerViewBindingConstants {
     public static final String CHANNEL_SHADE_SECONDARY_POSITION = "secondary";
     public static final String CHANNEL_SHADE_VANE = "vane";
     public static final String CHANNEL_SHADE_LOW_BATTERY = "lowBattery";
+    public static final String CHANNEL_SHADE_BATTERY_LEVEL = "batteryLevel";
     public static final String CHANNEL_SHADE_BATTERY_VOLTAGE = "batteryVoltage";
     public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength";
 
index 960d182fddd7e165d54600235e971fdd1c52ad82..70bf65bdd75ed05d52a67d9d9553b12f453374b4 100644 (file)
@@ -137,7 +137,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
         if (shadeData != null) {
             updateStatus(ThingStatus.ONLINE);
             updateBindingStates(shadeData.positions);
-            updateState(CHANNEL_SHADE_LOW_BATTERY, shadeData.batteryStatus == 1 ? OnOffType.ON : OnOffType.OFF);
+            updateBatteryLevel(shadeData.batteryStatus);
             updateState(CHANNEL_SHADE_BATTERY_VOLTAGE, new QuantityType<>(shadeData.batteryStrength / 10, Units.VOLT));
             updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
         } else {
@@ -157,6 +157,26 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
         }
     }
 
+    private void updateBatteryLevel(int batteryStatus) {
+        int mappedValue;
+        switch (batteryStatus) {
+            case 1: // Low
+                mappedValue = 10;
+                break;
+            case 2: // Medium
+                mappedValue = 50;
+                break;
+            case 3: // High
+            case 4: // Plugged in
+                mappedValue = 100;
+                break;
+            default: // No status available (0) or invalid
+                return;
+        }
+        updateState(CHANNEL_SHADE_LOW_BATTERY, batteryStatus == 1 ? OnOffType.ON : OnOffType.OFF);
+        updateState(CHANNEL_SHADE_BATTERY_LEVEL, new DecimalType(mappedValue));
+    }
+
     private void moveShade(ActuatorClass actuatorClass, CoordinateSystem coordSys, int newPercent) {
         try {
             HDPowerViewHubHandler bridge;
index 19e8e9a8a18f7d46eef0eac51160b2beb68eff8a..9794e8368aa5fbb34239744a81276105a29cf30d 100644 (file)
@@ -48,6 +48,7 @@
                        </channel>
                        <channel id="vane" typeId="shade-vane"/>
                        <channel id="lowBattery" typeId="system.low-battery"/>
+                       <channel id="batteryLevel" typeId="system.battery-level"/>
                        <channel id="batteryVoltage" typeId="battery-voltage"/>
                        <channel id="signalStrength" typeId="system.signal-strength"/>
                </channels>
index 75a56d6102958b49df8ee10a3ea99b90f26baced..8fd7e844c565dc026be8c51cc718395788bd96cd 100644 (file)
@@ -356,6 +356,8 @@ public class HDPowerViewJUnitTests {
             pos = shadePos.getState(PRIMARY_ACTUATOR, VANE_COORDS);
             assertEquals(UnDefType.class, pos.getClass());
 
+            assertEquals(3, shadeData.batteryStatus);
+
             assertEquals(4, shadeData.signalStrength);
         } catch (JsonParseException e) {
             fail(e.getMessage());
index 4e0e8a7d5291d15b6da3f1f08008868bbf5cfa31..ff4e03e01c00a02a62964e3ae74a66920fde0193 100644 (file)
@@ -6,8 +6,8 @@
                {
                        "id": 63778,
                        "type": 8,
-                       "batteryStatus": 0,
-                       "batteryStrength": 0,
+                       "batteryStatus": 3,
+                       "batteryStrength": 168,
                        "roomId": 891,
                        "firmware": {
                                "revision": 1,