rework color system and make it work with drivers.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -269,7 +269,7 @@ func (b *Bridge) MakeCongruent(ctx context.Context) (int, error) {
|
||||
lightsOut := light.Power != nil && !device.State.Power
|
||||
if !lightsOut {
|
||||
if light.ColorTemperature != nil && device.State.Color.IsKelvin() {
|
||||
mirek := 1000000 / device.State.Color.Kelvin
|
||||
mirek := 1000000 / *device.State.Color.K
|
||||
if mirek < light.ColorTemperature.MirekSchema.MirekMinimum {
|
||||
mirek = light.ColorTemperature.MirekSchema.MirekMinimum
|
||||
}
|
||||
@@ -280,9 +280,10 @@ func (b *Bridge) MakeCongruent(ctx context.Context) (int, error) {
|
||||
update.Mirek = &mirek
|
||||
changed = true
|
||||
}
|
||||
} else if xy, ok := device.State.Color.ToXY(); ok && light.Color != nil {
|
||||
xy = light.Color.Gamut.Conform(xy).Round()
|
||||
} else if xyColor, ok := device.State.Color.ToXY(); ok && light.Color != nil {
|
||||
xy := light.Color.Gamut.Conform(*xyColor.XY).Round()
|
||||
if xy.DistanceTo(light.Color.XY) > 0.0009 || (light.ColorTemperature != nil && light.ColorTemperature.Mirek != nil) {
|
||||
log.Println(xyColor.String(), device.State.Color.String())
|
||||
update.ColorXY = &xy
|
||||
changed = true
|
||||
}
|
||||
@@ -419,9 +420,7 @@ func (b *Bridge) GenerateDevices() []models.Device {
|
||||
}
|
||||
if light.ColorTemperature != nil {
|
||||
if light.ColorTemperature.Mirek != nil {
|
||||
device.State.Color = models.ColorValue{
|
||||
Kelvin: int(1000000 / *light.ColorTemperature.Mirek),
|
||||
}
|
||||
device.State.Color.SetK(1000000 / *light.ColorTemperature.Mirek)
|
||||
}
|
||||
device.Capabilities = append(device.Capabilities, models.DCColorKelvin)
|
||||
device.DriverProperties["maxTemperature"] = 1000000 / light.ColorTemperature.MirekSchema.MirekMinimum
|
||||
@@ -530,9 +529,11 @@ func (b *Bridge) applyPatches(patches []ResourceData) {
|
||||
resCopy.Color = &cp
|
||||
resCopy.Color.XY = patch.Color.XY
|
||||
|
||||
cp2 := *resCopy.ColorTemperature
|
||||
resCopy.ColorTemperature = &cp2
|
||||
resCopy.ColorTemperature.Mirek = nil
|
||||
if resCopy.ColorTemperature != nil {
|
||||
cp2 := *resCopy.ColorTemperature
|
||||
resCopy.ColorTemperature = &cp2
|
||||
resCopy.ColorTemperature.Mirek = nil
|
||||
}
|
||||
}
|
||||
if patch.ColorTemperature != nil && resCopy.ColorTemperature != nil {
|
||||
cp := *resCopy.ColorTemperature
|
||||
|
||||
Reference in New Issue
Block a user