[hdpowerview] Add new battery level channel (#11206)

* Introduce new batteryLevel channel.

Fixes #11205

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
jlaur 2021-09-08 20:36:59 +02:00 committed by GitHub
parent 8f836a08ea
commit 56a0449ce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 4 deletions

View 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. 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 | | 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. | | 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). | | 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). | | 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. | | 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. | | 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) | | signalStrength | Number | Signal strength (0 for no or unknown signal, 1 for weak, 2 for average, 3 for good or 4 for excellent) |

View File

@ -41,6 +41,7 @@ public class HDPowerViewBindingConstants {
public static final String CHANNEL_SHADE_SECONDARY_POSITION = "secondary"; public static final String CHANNEL_SHADE_SECONDARY_POSITION = "secondary";
public static final String CHANNEL_SHADE_VANE = "vane"; public static final String CHANNEL_SHADE_VANE = "vane";
public static final String CHANNEL_SHADE_LOW_BATTERY = "lowBattery"; 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_BATTERY_VOLTAGE = "batteryVoltage";
public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength"; public static final String CHANNEL_SHADE_SIGNAL_STRENGTH = "signalStrength";

View File

@ -137,7 +137,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
if (shadeData != null) { if (shadeData != null) {
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
updateBindingStates(shadeData.positions); 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_BATTERY_VOLTAGE, new QuantityType<>(shadeData.batteryStrength / 10, Units.VOLT));
updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength)); updateState(CHANNEL_SHADE_SIGNAL_STRENGTH, new DecimalType(shadeData.signalStrength));
} else { } 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) { private void moveShade(ActuatorClass actuatorClass, CoordinateSystem coordSys, int newPercent) {
try { try {
HDPowerViewHubHandler bridge; HDPowerViewHubHandler bridge;

View File

@ -48,6 +48,7 @@
</channel> </channel>
<channel id="vane" typeId="shade-vane"/> <channel id="vane" typeId="shade-vane"/>
<channel id="lowBattery" typeId="system.low-battery"/> <channel id="lowBattery" typeId="system.low-battery"/>
<channel id="batteryLevel" typeId="system.battery-level"/>
<channel id="batteryVoltage" typeId="battery-voltage"/> <channel id="batteryVoltage" typeId="battery-voltage"/>
<channel id="signalStrength" typeId="system.signal-strength"/> <channel id="signalStrength" typeId="system.signal-strength"/>
</channels> </channels>

View File

@ -356,6 +356,8 @@ public class HDPowerViewJUnitTests {
pos = shadePos.getState(PRIMARY_ACTUATOR, VANE_COORDS); pos = shadePos.getState(PRIMARY_ACTUATOR, VANE_COORDS);
assertEquals(UnDefType.class, pos.getClass()); assertEquals(UnDefType.class, pos.getClass());
assertEquals(3, shadeData.batteryStatus);
assertEquals(4, shadeData.signalStrength); assertEquals(4, shadeData.signalStrength);
} catch (JsonParseException e) { } catch (JsonParseException e) {
fail(e.getMessage()); fail(e.getMessage());

View File

@ -6,8 +6,8 @@
{ {
"id": 63778, "id": 63778,
"type": 8, "type": 8,
"batteryStatus": 0, "batteryStatus": 3,
"batteryStrength": 0, "batteryStrength": 168,
"roomId": 891, "roomId": 891,
"firmware": { "firmware": {
"revision": 1, "revision": 1,