[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:
parent
8f836a08ea
commit
56a0449ce1
|
@ -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) |
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ public class HDPowerViewShadeHandler extends AbstractHubbedThingHandler {
|
|||
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 {
|
||||
|
@ -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) {
|
||||
try {
|
||||
HDPowerViewHubHandler bridge;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -356,6 +356,8 @@ public class HDPowerViewJUnitTests {
|
|||
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());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
{
|
||||
"id": 63778,
|
||||
"type": 8,
|
||||
"batteryStatus": 0,
|
||||
"batteryStrength": 0,
|
||||
"batteryStatus": 3,
|
||||
"batteryStrength": 168,
|
||||
"roomId": 891,
|
||||
"firmware": {
|
||||
"revision": 1,
|
||||
|
|
Loading…
Reference in New Issue