[miio] fix reported brightness for yeelight (#15611)

Fix reported brightness for yeelight when powered off.
This will fix wrong power switch visualization in the OH UI.

related to issue:
https://community.openhab.org/t/miio-and-yeelight-rgb-bulbs-behavior/135788/9

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2023-09-23 18:38:58 +02:00 committed by GitHub
parent 1da4dca257
commit 7a0d05781a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -61,14 +61,22 @@ public class Conversions {
* *
* @param RGB * @param RGB
* @param map with device variables containing the brightness info * @param map with device variables containing the brightness info
* @param report brightness 0 on power off
* @return HSV * @return HSV
*/ */
private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables) private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables,
throws ClassCastException, IllegalStateException { boolean powerDependent) throws ClassCastException, IllegalStateException {
int bright = 100; int bright = 100;
if (deviceVariables != null) { if (deviceVariables != null) {
JsonElement lastBright = (JsonElement) deviceVariables.getOrDefault("bright", new JsonPrimitive(100)); JsonElement lastBright = (JsonElement) deviceVariables.getOrDefault("bright", new JsonPrimitive(100));
bright = lastBright.getAsInt(); bright = lastBright.getAsInt();
if (powerDependent) {
String lastPower = ((JsonElement) deviceVariables.getOrDefault("power", new JsonPrimitive("on")))
.getAsString();
if (lastPower.toLowerCase().contentEquals("off")) {
bright = 0;
}
}
} }
if (rgbValue.isJsonPrimitive() if (rgbValue.isJsonPrimitive()
&& (rgbValue.getAsJsonPrimitive().isNumber() || rgbValue.getAsString().matches("^[0-9]+$"))) { && (rgbValue.getAsJsonPrimitive().isNumber() || rgbValue.getAsString().matches("^[0-9]+$"))) {
@ -215,7 +223,9 @@ public class Conversions {
case "TANKLEVEL": case "TANKLEVEL":
return tankLevel(value); return tankLevel(value);
case "ADDBRIGHTTOHSV": case "ADDBRIGHTTOHSV":
return addBrightToHSV(value, deviceVariables); return addBrightToHSV(value, deviceVariables, false);
case "ADDBRIGHTTOHSVPOWER":
return addBrightToHSV(value, deviceVariables, true);
case "BRGBTOHSV": case "BRGBTOHSV":
return bRGBtoHSV(value); return bRGBtoHSV(value);
case "DEVICEDATATAB": case "DEVICEDATATAB":

View File

@ -121,7 +121,7 @@
"channel": "rgbColor", "channel": "rgbColor",
"type": "Color", "type": "Color",
"refresh": true, "refresh": true,
"transformation": "addBrightToHSV", "transformation": "addBrightToHSVPower",
"ChannelGroup": "actions", "ChannelGroup": "actions",
"actions": [ "actions": [
{ {