Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[miio] fix reported brightness for yeelight #15611

Merged
merged 1 commit into from Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,14 +61,22 @@ private static JsonElement bRGBtoHSV(JsonElement bRGB) throws ClassCastException
*
* @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]+$"))) {
Expand Down Expand Up @@ -215,7 +223,9 @@ public static JsonElement execute(String transformation, JsonElement value, Map<
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":
Expand Down
Expand Up @@ -121,7 +121,7 @@
"channel": "rgbColor",
"type": "Color",
"refresh": true,
"transformation": "addBrightToHSV",
"transformation": "addBrightToHSVPower",
"ChannelGroup": "actions",
"actions": [
{
Expand Down