From 9ec6f7d12eafdf10715f751c49d8e206c086a106 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Mon, 25 Jul 2022 12:56:03 +0200 Subject: [PATCH] Add shade RF RSSI for hub/repeater (#13096) Signed-off-by: Jacob Laursen --- .../org.openhab.binding.hdpowerview/README.md | 7 ++++- .../internal/HDPowerViewBindingConstants.java | 2 ++ .../handler/HDPowerViewShadeHandler.java | 29 +++++++++++++++++-- .../OH-INF/i18n/hdpowerview.properties | 6 ++++ .../main/resources/OH-INF/thing/channels.xml | 8 +++++ .../src/main/resources/OH-INF/thing/shade.xml | 8 +++++ 6 files changed, 57 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.hdpowerview/README.md b/bundles/org.openhab.binding.hdpowerview/README.md index d7ef2d2ad..146813ec5 100644 --- a/bundles/org.openhab.binding.hdpowerview/README.md +++ b/bundles/org.openhab.binding.hdpowerview/README.md @@ -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 diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewBindingConstants.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewBindingConstants.java index be154bc2e..02c61d907 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewBindingConstants.java +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/HDPowerViewBindingConstants.java @@ -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"; diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java index 27998b276..391cfaf44 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java +++ b/bundles/org.openhab.binding.hdpowerview/src/main/java/org/openhab/binding/hdpowerview/internal/handler/HDPowerViewShadeHandler.java @@ -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) { diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties index 8838c2da8..6aeb6076f 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties +++ b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/i18n/hdpowerview.properties @@ -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 diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/channels.xml index 110c0a28a..8ec5e9c5a 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/channels.xml @@ -51,6 +51,14 @@ + + Number:Power + + Received Signal Strength Indicator + QualityOfService + + + String diff --git a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/shade.xml b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/shade.xml index 2466dc9f4..a8dd16876 100644 --- a/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/shade.xml +++ b/bundles/org.openhab.binding.hdpowerview/src/main/resources/OH-INF/thing/shade.xml @@ -23,6 +23,14 @@ + + + Received Signal Strength Indicator for Hub + + + + Received Signal Strength Indicator for Repeater +