[deconz] Add support for lowbattery flag from state response (#12422)

* Add support for lowbattery flag from state response

Signed-off-by: Johannes Ott <mail@johannes-ott.net>
This commit is contained in:
Johannes Ott 2022-03-05 21:51:21 +01:00 committed by GitHub
parent 52c21a35a3
commit 8a394c6427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -66,6 +66,11 @@ public class SensorState {
public @Nullable Float power;
/** Batttery sensors provide this value */
public @Nullable Integer battery;
/**
* Some battery sensors (especially Tuya driven devices) provide this boolean
* instead of battery level
*/
public @Nullable Boolean lowbattery;
/** Consumption sensors provide this value in Watts/hour. */
public @Nullable Float consumption;
/** Power sensors provide this value in Volt. */

View File

@ -138,6 +138,10 @@ public abstract class SensorBaseThingHandler extends DeconzBaseThingHandler {
createChannel(CHANNEL_BATTERY_LOW, ChannelKind.STATE);
}
if (sensorState.lowbattery != null) {
createChannel(CHANNEL_BATTERY_LOW, ChannelKind.STATE);
}
createTypeSpecificChannels(sensorConfig, sensorState);
ignoreConfigurationUpdate = false;
@ -210,6 +214,12 @@ public abstract class SensorBaseThingHandler extends DeconzBaseThingHandler {
updateState(channelUID, Util.convertTimestampToDateTime(lastUpdated));
}
break;
case CHANNEL_BATTERY_LOW:
Boolean lowBattery = newState.lowbattery;
if (lowBattery != null) {
updateState(channelUID, OnOffType.from(lowBattery));
}
break;
default:
// other cases covered by sub-class
}