]> git.basschouten.com Git - openhab-addons.git/commitdiff
Add shade RF RSSI for hub/repeater (#13096)
authorJacob Laursen <jacob-github@vindvejr.dk>
Mon, 25 Jul 2022 10:56:03 +0000 (12:56 +0200)
committerGitHub <noreply@github.com>
Mon, 25 Jul 2022 10:56:03 +0000 (12:56 +0200)
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/i18n/hdpowerview.properties
bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/channels.xml
bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/shade.xml

index d7ef2d2addd7ae2a8e5645b32820bc9ece8e5b53..146813ec5be4fac94cf657f17e5009205229681f 100644 (file)
@@ -64,7 +64,6 @@ PowerView app. However, the configuration parameters are described below.
 
 #### Thing Configuration for PowerView Repeaters
 
-
 | Configuration Parameter | Description |
 |-------------------------|-------------|
 | id                      | The ID of the PowerView repeater in the app. Must be an integer. |
@@ -100,6 +99,10 @@ All of these channels appear in the binding, but only those which have a physica
 | 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) |
+| hubRssi        | Number:Power             | Received Signal Strength Indicator for Hub |
+| repeaterRssi   | Number:Power             | Received Signal Strength Indicator for Repeater |
+
+Please note that RSSI values will only be updated upon manual request by a `REFRESH` command (e.g. in a rule).
 
 ### Channels for Repeaters (Thing type `repeater`)
 
@@ -210,6 +213,8 @@ For single shades the refresh takes the item's channel into consideration:
 | batteryLevel   | Battery           |
 | batteryVoltage | Battery           |
 | signalStrength | Survey            |
+| hubRssi        | Survey            |
+| repeaterRssi   | Survey            |
 
 ## Full Example
 
index be154bc2ec45f229dcc673191f9e1aa6e35a3d6a..02c61d907f547a8ec2d0163150a54c75c0b622ff 100644 (file)
@@ -46,6 +46,8 @@ public class HDPowerViewBindingConstants {
     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";
+    public static final String CHANNEL_SHADE_HUB_RSSI = "hubRssi";
+    public static final String CHANNEL_SHADE_REPEATER_RSSI = "repeaterRssi";
 
     public static final String CHANNEL_REPEATER_COLOR = "color";
     public static final String CHANNEL_REPEATER_BRIGHTNESS = "brightness";
index 27998b2768d9736ed680e88fb8c69cd680e02f81..391cfaf448f3cd91db3e51a402666be011dd7179 100644 (file)
@@ -150,6 +150,8 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
                     requestRefreshShadeBatteryLevel();
                     break;
                 case CHANNEL_SHADE_SIGNAL_STRENGTH:
+                case CHANNEL_SHADE_HUB_RSSI:
+                case CHANNEL_SHADE_REPEATER_RSSI:
                     requestRefreshShadeSurvey();
                     break;
             }
@@ -534,15 +536,32 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
                             surveyData.forEach(data -> joiner.add(data.toString()));
                             logger.debug("Survey response for shade {}: {}", shadeId, joiner.toString());
                         }
+
+                        int hubRssi = Integer.MAX_VALUE;
+                        int repeaterRssi = Integer.MAX_VALUE;
+                        for (SurveyData survey : surveyData) {
+                            if (survey.neighborId == 0) {
+                                hubRssi = survey.rssi;
+                            } else {
+                                repeaterRssi = survey.rssi;
+                            }
+                        }
+                        updateState(CHANNEL_SHADE_HUB_RSSI, hubRssi == Integer.MAX_VALUE ? UnDefType.UNDEF
+                                : new QuantityType<>(hubRssi, Units.DECIBEL_MILLIWATTS));
+                        updateState(CHANNEL_SHADE_REPEATER_RSSI, repeaterRssi == Integer.MAX_VALUE ? UnDefType.UNDEF
+                                : new QuantityType<>(repeaterRssi, Units.DECIBEL_MILLIWATTS));
+
                         shadeData = webTargets.getShade(shadeId);
                         updateSignalStrengthState(shadeData.signalStrength);
                     } else {
                         logger.info("No data from shade {} survey", shadeId);
                         /*
-                         * Setting channel to UNDEF here would be reverted on next poll, since
-                         * signal strength is part of shade response. So leaving current value,
+                         * Setting signal strength channel to UNDEF here would be reverted on next poll,
+                         * since signal strength is part of shade response. So leaving current value,
                          * even though refreshing the value failed.
                          */
+                        updateState(CHANNEL_SHADE_HUB_RSSI, UnDefType.UNDEF);
+                        updateState(CHANNEL_SHADE_REPEATER_RSSI, UnDefType.UNDEF);
                     }
                     break;
                 case BATTERY_LEVEL:
@@ -559,6 +578,12 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
             } else {
                 logger.warn("Bridge returned a bad JSON response: {} -> {}", e.getMessage(), cause.getMessage());
             }
+            // Survey calls are unreliable and often returns "{}" as payload. For repeater RSSI tracking to be useful,
+            // we need to reset channels also in this case.
+            if (kind == RefreshKind.SURVEY) {
+                updateState(CHANNEL_SHADE_HUB_RSSI, UnDefType.UNDEF);
+                updateState(CHANNEL_SHADE_REPEATER_RSSI, UnDefType.UNDEF);
+            }
         } catch (HubMaintenanceException e) {
             // exceptions are logged in HDPowerViewWebTargets
         } catch (HubShadeTimeoutException e) {
index 8838c2da867986ee02d0aeb2260e0ffde1dcf992..6aeb6076f95824e953eff5b36d3bf314fffe5026 100644 (file)
@@ -13,6 +13,10 @@ thing-type.hdpowerview.repeater.channel.brightness.description = Controls the br
 thing-type.hdpowerview.repeater.channel.color.description = Controls the color of the LED ring
 thing-type.hdpowerview.shade.label = PowerView Shade
 thing-type.hdpowerview.shade.description = Hunter Douglas (Luxaflex) PowerView Shade
+thing-type.hdpowerview.shade.channel.hubRssi.label = Hub RSSI
+thing-type.hdpowerview.shade.channel.hubRssi.description = Received Signal Strength Indicator for Hub
+thing-type.hdpowerview.shade.channel.repeaterRssi.label = Repeater RSSI
+thing-type.hdpowerview.shade.channel.repeaterRssi.description = Received Signal Strength Indicator for Repeater
 thing-type.hdpowerview.shade.channel.secondary.label = Secondary Position
 thing-type.hdpowerview.shade.channel.secondary.description = The secondary vertical position (on top-down/bottom-up shades)
 
@@ -47,6 +51,8 @@ channel-type.hdpowerview.repeater-blinking-enabled.description = Blink during co
 channel-type.hdpowerview.repeater-identify.label = Identify
 channel-type.hdpowerview.repeater-identify.description = Flash repeater to identify
 channel-type.hdpowerview.repeater-identify.command.option.IDENTIFY = Identify
+channel-type.hdpowerview.rssi.label = RSSI
+channel-type.hdpowerview.rssi.description = Received Signal Strength Indicator
 channel-type.hdpowerview.scene-activate.label = Activate
 channel-type.hdpowerview.scene-group-activate.label = Activate
 channel-type.hdpowerview.shade-command.label = Command
index 110c0a28aa67e92fbab25f311d85c5c0faf613e0..8ec5e9c5a15475abc6faff941a2025c17f0647b2 100644 (file)
                <state pattern="%.1f %unit%" readOnly="true"/>
        </channel-type>
 
+       <channel-type id="rssi" advanced="true">
+               <item-type>Number:Power</item-type>
+               <label>RSSI</label>
+               <description>Received Signal Strength Indicator</description>
+               <category>QualityOfService</category>
+               <state readOnly="true" pattern="%d %unit%"></state>
+       </channel-type>
+
        <channel-type id="repeater-identify">
                <item-type>String</item-type>
                <label>Identify</label>
index 2466dc9f4e858f9741f49f48823d73c2db9f4950..a8dd168767b7712f1583c739a991207151fd3068 100644 (file)
                        <channel id="batteryLevel" typeId="system.battery-level"/>
                        <channel id="batteryVoltage" typeId="battery-voltage"/>
                        <channel id="signalStrength" typeId="system.signal-strength"/>
+                       <channel id="hubRssi" typeId="rssi">
+                               <label>Hub RSSI</label>
+                               <description>Received Signal Strength Indicator for Hub</description>
+                       </channel>
+                       <channel id="repeaterRssi" typeId="rssi">
+                               <label>Repeater RSSI</label>
+                               <description>Received Signal Strength Indicator for Repeater</description>
+                       </channel>
                </channels>
 
                <properties>