Skip to content

Commit

Permalink
[hdpowerview] Add new battery level channel (#11206)
Browse files Browse the repository at this point in the history
* Introduce new batteryLevel channel.

Fixes #11205

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur committed Sep 8, 2021
1 parent 8f836a0 commit 56a0449
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bundles/org.openhab.binding.hdpowerview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void onReceiveUpdate(@Nullable ShadeData shadeData) {
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 {
Expand All @@ -157,6 +157,26 @@ private void updateBindingStates(@Nullable ShadePosition shadePos) {
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public void testOfflineJsonParsing() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
{
"id": 63778,
"type": 8,
"batteryStatus": 0,
"batteryStrength": 0,
"batteryStatus": 3,
"batteryStrength": 168,
"roomId": 891,
"firmware": {
"revision": 1,
Expand Down

0 comments on commit 56a0449

Please sign in to comment.