rework color system and make it work with drivers.
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-02-21 19:27:42 +01:00
parent d5cf30ea4b
commit df865574bf
16 changed files with 468 additions and 179 deletions
+6 -4
View File
@@ -169,9 +169,11 @@ func (b *Bridge) Run(ctx context.Context, debug bool) error {
state.deviceState = &models.DeviceState{
Power: p.On,
Color: models.ColorValue{
Hue: p.Hue,
Saturation: p.Sat,
Kelvin: p.Kelvin,
HS: &models.ColorHS{
Hue: p.Hue,
Sat: p.Sat,
},
K: &p.Kelvin,
},
Intensity: p.Bri,
}
@@ -204,7 +206,7 @@ func (b *Bridge) Run(ctx context.Context, debug bool) error {
b.checkAndUpdateState(state)
}
if time.Since(state.discoveredTime) > time.Second*10 && time.Since(state.fwSpamTime) > time.Second * 30 {
if time.Since(state.discoveredTime) > time.Second*10 && time.Since(state.fwSpamTime) > time.Second*30 {
state.fwSpamTime = time.Now()
if state.firmware == nil {
+17 -8
View File
@@ -36,17 +36,21 @@ func (s *State) generateUpdate() []Payload {
return results
}
c := s.deviceState.Color
c, ok := s.deviceState.Color.ToHSK()
if !ok {
c, _ = models.ParseColorValue("hsk:0,0,4000")
}
l := s.lightState
di := s.deviceState.Intensity
k := c.Kelvin
k := *c.K
if k == 0 {
k = 4000
}
if !equalish(c.Hue, l.Hue) || !equalish(c.Saturation, l.Sat) || !equalish(di, l.Bri) || k != l.Kelvin {
if !equalish(c.HS.Hue, l.Hue) || !equalish(c.HS.Sat, l.Sat) || !equalish(di, l.Bri) || k != l.Kelvin {
results = append(results, &SetColor{
Hue: c.Hue,
Sat: c.Saturation,
Hue: c.HS.Hue,
Sat: c.HS.Sat,
Bri: di,
Kelvin: k,
TransitionTime: time.Millisecond * 150,
@@ -72,11 +76,16 @@ func (s *State) handleAck(seq uint8) {
prevLabel = s.lightState.Label
}
color, ok := s.deviceState.Color.ToHSK()
if !ok {
color, _ = models.ParseColorValue("hsk:0,0,4000")
}
s.lightState = &LightState{
Hue: s.deviceState.Color.Hue,
Sat: s.deviceState.Color.Saturation,
Hue: color.HS.Hue,
Sat: color.HS.Sat,
Bri: s.deviceState.Intensity,
Kelvin: s.deviceState.Color.Kelvin,
Kelvin: *color.K,
On: s.deviceState.Power,
Label: prevLabel,
}