Skip to content

Commit 7938fd6

Browse files
committed
Fix comparison of scene action brightness
1 parent 13b6405 commit 7938fd6

2 files changed

Lines changed: 387 additions & 3 deletions

File tree

src/main/java/at/sv/hue/api/hue/HueApiImpl.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.Collection;
4848
import java.util.EnumSet;
4949
import java.util.HashMap;
50-
import java.util.HashSet;
5150
import java.util.List;
5251
import java.util.Locale;
5352
import java.util.Map;
@@ -650,7 +649,29 @@ private static Action.GradientPoint createGradientPoint(Pair<Double, Double> pai
650649

651650
private static boolean actionsDiffer(Scene scene, List<SceneAction> actions) {
652651
List<SceneAction> currentActions = scene.getActions();
653-
return !new HashSet<>(currentActions).containsAll(actions);
652+
return !actions.stream().allMatch(action -> currentActions.stream().anyMatch(
653+
current -> sceneActionsMatch(current, action)));
654+
}
655+
656+
private static boolean sceneActionsMatch(SceneAction a, SceneAction b) {
657+
if (!Objects.equals(a.getTarget(), b.getTarget())) {
658+
return false;
659+
}
660+
Action aa = a.getAction();
661+
Action ba = b.getAction();
662+
return Objects.equals(aa.getOn(), ba.getOn()) &&
663+
dimmingMatches(aa.getDimming(), ba.getDimming()) &&
664+
Objects.equals(aa.getColor(), ba.getColor()) &&
665+
Objects.equals(aa.getColor_temperature(), ba.getColor_temperature()) &&
666+
Objects.equals(aa.getEffects_v2(), ba.getEffects_v2()) &&
667+
Objects.equals(aa.getGradient(), ba.getGradient()) &&
668+
Objects.equals(aa.getDynamics(), ba.getDynamics());
669+
}
670+
671+
private static boolean dimmingMatches(Dimming a, Dimming b) {
672+
if (a == null && b == null) return true;
673+
if (a == null || b == null) return false;
674+
return Math.abs(a.getBrightness() - b.getBrightness()) < 0.5;
654675
}
655676

656677
private String createScene(Scene newScene) {

0 commit comments

Comments
 (0)