some more stuffs.
This commit is contained in:
+50
-58
@@ -443,68 +443,60 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Handle power first
|
||||
if desired.Power != nil && active.Power != nil && *desired.Power != *active.Power {
|
||||
updates["light/"+*lightID] = ResourceUpdate{
|
||||
Power: gentools.Ptr(*desired.Power),
|
||||
TransitionDuration: gentools.Ptr(time.Millisecond * 101),
|
||||
}
|
||||
|
||||
newActiveState := activeStates[id]
|
||||
newActiveState.Power = gentools.Ptr(*desired.Power)
|
||||
|
||||
continue
|
||||
}
|
||||
if active.Power != nil && !*active.Power {
|
||||
// Don't do more with shut-off-light.
|
||||
continue
|
||||
}
|
||||
|
||||
updated := false
|
||||
update := ResourceUpdate{}
|
||||
|
||||
if active.Color != nil && desired.Color != nil {
|
||||
ac := *active.Color
|
||||
dc := *desired.Color
|
||||
|
||||
if !dc.IsKelvin() || !colorFlags[id].IsWarmWhite() {
|
||||
dc, _ = dc.ToXY()
|
||||
dc.XY = gentools.Ptr(light.Color.Gamut.Conform(*dc.XY))
|
||||
}
|
||||
|
||||
if dc.XY != nil {
|
||||
if ac.K != nil {
|
||||
ac.K = gentools.Ptr(1000000 / (1000000 / *ac.K))
|
||||
}
|
||||
|
||||
acXY, _ := ac.ToXY()
|
||||
dist := dc.XY.DistanceTo(*acXY.XY)
|
||||
if dist > 0.0002 {
|
||||
update.ColorXY = gentools.Ptr(*dc.XY)
|
||||
updated = true
|
||||
}
|
||||
} else {
|
||||
dcMirek := 1000000 / *dc.K
|
||||
if dcMirek < light.ColorTemperature.MirekSchema.MirekMinimum {
|
||||
dcMirek = light.ColorTemperature.MirekSchema.MirekMinimum
|
||||
} else if dcMirek > light.ColorTemperature.MirekSchema.MirekMaximum {
|
||||
dcMirek = light.ColorTemperature.MirekSchema.MirekMaximum
|
||||
}
|
||||
acMirek := 0
|
||||
if ac.K != nil {
|
||||
acMirek = 1000000 / *ac.K
|
||||
}
|
||||
if acMirek != dcMirek {
|
||||
update.Mirek = &dcMirek
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
// Handle power first
|
||||
if desired.Power != nil && active.Power != nil && *desired.Power != *active.Power {
|
||||
update.Power = gentools.Ptr(*desired.Power)
|
||||
updated = true
|
||||
}
|
||||
|
||||
if active.Intensity != nil && desired.Intensity != nil {
|
||||
if math.Abs(*active.Intensity-*desired.Intensity) >= 0.01 {
|
||||
update.Brightness = gentools.Ptr(*desired.Intensity * 100)
|
||||
updated = true
|
||||
// Only do the rest if there's power.
|
||||
if desired.Power == nil || *desired.Power {
|
||||
if active.Color != nil && desired.Color != nil {
|
||||
ac := *active.Color
|
||||
dc := *desired.Color
|
||||
|
||||
if !dc.IsKelvin() || !colorFlags[id].IsWarmWhite() {
|
||||
dc, _ = dc.ToXY()
|
||||
dc.XY = gentools.Ptr(light.Color.Gamut.Conform(*dc.XY))
|
||||
}
|
||||
|
||||
if dc.XY != nil {
|
||||
if ac.K != nil {
|
||||
ac.K = gentools.Ptr(1000000 / (1000000 / *ac.K))
|
||||
}
|
||||
|
||||
acXY, _ := ac.ToXY()
|
||||
dist := dc.XY.DistanceTo(*acXY.XY)
|
||||
if dist > 0.0002 {
|
||||
update.ColorXY = gentools.Ptr(*dc.XY)
|
||||
updated = true
|
||||
}
|
||||
} else {
|
||||
dcMirek := 1000000 / *dc.K
|
||||
if dcMirek < light.ColorTemperature.MirekSchema.MirekMinimum {
|
||||
dcMirek = light.ColorTemperature.MirekSchema.MirekMinimum
|
||||
} else if dcMirek > light.ColorTemperature.MirekSchema.MirekMaximum {
|
||||
dcMirek = light.ColorTemperature.MirekSchema.MirekMaximum
|
||||
}
|
||||
acMirek := 0
|
||||
if ac.K != nil {
|
||||
acMirek = 1000000 / *ac.K
|
||||
}
|
||||
if acMirek != dcMirek {
|
||||
update.Mirek = &dcMirek
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if active.Intensity != nil && desired.Intensity != nil {
|
||||
if math.Abs(*active.Intensity-*desired.Intensity) >= 0.01 {
|
||||
update.Brightness = gentools.Ptr(*desired.Intensity * 100)
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +507,7 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
|
||||
}
|
||||
|
||||
if len(updates) > 0 {
|
||||
timeout, cancel := context.WithTimeout(ctx, time.Second)
|
||||
timeout, cancel := context.WithTimeout(ctx, time.Millisecond*500*time.Duration(len(updates)))
|
||||
|
||||
eg, ctx := errgroup.WithContext(timeout)
|
||||
for key := range updates {
|
||||
|
||||
@@ -210,8 +210,10 @@ func (res *ResourceData) GenerateEvent(hostname string, resources map[string]*Re
|
||||
hwMeta.Icon = "hue_lightbulb_e14"
|
||||
case "sultan_bulb":
|
||||
hwMeta.Icon = "hue_lightbulb_e27"
|
||||
case "hue_signe":
|
||||
hwMeta.Icon = "hue_signe"
|
||||
case "hue_play":
|
||||
hwMeta.Icon = "hue_playbar"
|
||||
case "hue_signe", "hue_go":
|
||||
hwMeta.Icon = res.ProductData.ProductArchetype
|
||||
case "unknown_archetype":
|
||||
switch res.ProductData.ProductName {
|
||||
case "Hue motion sensor":
|
||||
|
||||
Reference in New Issue
Block a user