@@ -42,11 +42,18 @@ func updateScenes() {
42
42
}
43
43
44
44
func updateSceneForSchedule (scene * hue.Scene , lightSchedule LightSchedule ) {
45
+ // Scene returned by AllScenes() doesn't have LightStates populated
46
+ scene , err := bridge .bridge .SceneByID (scene .Id )
47
+ if err != nil {
48
+ log .Warningf ("🎨 %v" , err )
49
+ return
50
+ }
51
+
45
52
// Updating lights
46
53
var modifyScene hue.ModifyScene
47
54
modifyScene .Lights = toStringArray (lightSchedule .AssociatedDeviceIDs )
48
55
49
- _ , err : = scene .Modify (modifyScene )
56
+ _ , err = scene .Modify (modifyScene )
50
57
if err != nil {
51
58
log .Warningf ("🎨 %v" , err )
52
59
return
@@ -68,20 +75,26 @@ func updateSceneForSchedule(scene *hue.Scene, lightSchedule LightSchedule) {
68
75
69
76
state := interval .calculateLightStateInInterval (time .Now ())
70
77
71
- var modifyState hue.ModifyLightState
72
- modifyState .On = true // turn lights on when the scene is activated
78
+ for i , oldstate := range scene .LightStates {
79
+ if ! oldstate .On {
80
+ continue ;
81
+ }
73
82
74
- if state .ColorTemperature != - 1 {
75
- modifyState .ColorTemperature = uint16 (mapColorTemperature (state .ColorTemperature ))
76
- modifyState .Xy = colorTemperatureToXYColor (state .ColorTemperature )
77
- }
78
- if state .Brightness != - 1 {
79
- modifyState .Brightness = uint8 (mapBrightness (state .Brightness ))
80
- }
83
+ var modifyState hue.ModifyLightState
84
+ modifyState .On = true // turn lights on when the scene is activated
81
85
82
- _ , err = scene .ModifyLightStates (modifyState )
83
- if err != nil {
84
- log .Warningf ("🎨 %v" , err )
86
+ if state .ColorTemperature != - 1 {
87
+ modifyState .ColorTemperature = uint16 (mapColorTemperature (state .ColorTemperature ))
88
+ modifyState .Xy = colorTemperatureToXYColor (state .ColorTemperature )
89
+ }
90
+ if state .Brightness != - 1 {
91
+ modifyState .Brightness = uint8 (mapBrightness (state .Brightness ))
92
+ }
93
+
94
+ _ , err = scene .ModifyLightState (i , modifyState )
95
+ if err != nil {
96
+ log .Warningf ("🎨 %v" , err )
97
+ }
85
98
}
86
99
87
100
log .Debugf ("🎨 Successfully updated scene \" %s\" " , scene .Name )
0 commit comments