Skip to content

Commit

Permalink
[hdpowerview] Add new signal strength channel (openhab#11198)
Browse files Browse the repository at this point in the history
* Add new signal strength channel.

Fixes openhab#11197

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur authored Sep 4, 2021
1 parent 1f09c64 commit 88ca53a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.hdpowerview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ All of these channels appear in the binding, but only those which have a physica
| 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. |
| 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) |

### Roller Shutter Up/Down Position vs. Open/Close State

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public class HDPowerViewBindingConstants {

// List of all Channel ids
public static final String CHANNEL_SHADE_POSITION = "position";
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_VOLTAGE = "batteryVoltage";
public static final String CHANNEL_SHADE_SECONDARY_POSITION = "secondary";
public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength";

public static final String CHANNELTYPE_SCENE_ACTIVATE = "scene-activate";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static class ShadeData {
public boolean batteryIsLow;
public @Nullable ShadePosition positions;
public @Nullable Boolean timedOut;
public int signalStrength;

public String getName() {
return new String(Base64.getDecoder().decode(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openhab.binding.hdpowerview.internal.api.responses.Shade;
import org.openhab.binding.hdpowerview.internal.api.responses.Shades.ShadeData;
import org.openhab.binding.hdpowerview.internal.config.HDPowerViewShadeConfiguration;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
Expand Down Expand Up @@ -138,6 +139,7 @@ protected void onReceiveUpdate(@Nullable ShadeData shadeData) {
updateBindingStates(shadeData.positions);
updateState(CHANNEL_SHADE_LOW_BATTERY, shadeData.batteryStatus == 1 ? OnOffType.ON : OnOffType.OFF);
updateState(CHANNEL_SHADE_BATTERY_VOLTAGE, new QuantityType<>(shadeData.batteryStrength / 10, Units.VOLT));
updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<channel id="vane" typeId="shade-vane"/>
<channel id="lowBattery" typeId="system.low-battery"/>
<channel id="batteryVoltage" typeId="battery-voltage"/>
<channel id="signalStrength" typeId="system.signal-strength"/>
</channels>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ public void testOfflineJsonParsing() {

pos = shadePos.getState(PRIMARY_ACTUATOR, VANE_COORDS);
assertEquals(UnDefType.class, pos.getClass());

assertEquals(4, shadeData.signalStrength);
} catch (JsonParseException e) {
fail(e.getMessage());
}
Expand Down

0 comments on commit 88ca53a

Please sign in to comment.