mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[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:
parent
1da4dca257
commit
7a0d05781a
@ -61,14 +61,22 @@ public class Conversions {
|
||||
*
|
||||
* @param RGB
|
||||
* @param map with device variables containing the brightness info
|
||||
* @param report brightness 0 on power off
|
||||
* @return HSV
|
||||
*/
|
||||
private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables)
|
||||
throws ClassCastException, IllegalStateException {
|
||||
private static JsonElement addBrightToHSV(JsonElement rgbValue, @Nullable Map<String, Object> deviceVariables,
|
||||
boolean powerDependent) throws ClassCastException, IllegalStateException {
|
||||
int bright = 100;
|
||||
if (deviceVariables != null) {
|
||||
JsonElement lastBright = (JsonElement) deviceVariables.getOrDefault("bright", new JsonPrimitive(100));
|
||||
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()
|
||||
&& (rgbValue.getAsJsonPrimitive().isNumber() || rgbValue.getAsString().matches("^[0-9]+$"))) {
|
||||
@ -215,7 +223,9 @@ public class Conversions {
|
||||
case "TANKLEVEL":
|
||||
return tankLevel(value);
|
||||
case "ADDBRIGHTTOHSV":
|
||||
return addBrightToHSV(value, deviceVariables);
|
||||
return addBrightToHSV(value, deviceVariables, false);
|
||||
case "ADDBRIGHTTOHSVPOWER":
|
||||
return addBrightToHSV(value, deviceVariables, true);
|
||||
case "BRGBTOHSV":
|
||||
return bRGBtoHSV(value);
|
||||
case "DEVICEDATATAB":
|
||||
|
@ -121,7 +121,7 @@
|
||||
"channel": "rgbColor",
|
||||
"type": "Color",
|
||||
"refresh": true,
|
||||
"transformation": "addBrightToHSV",
|
||||
"transformation": "addBrightToHSVPower",
|
||||
"ChannelGroup": "actions",
|
||||
"actions": [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user