moar stuff.
This commit is contained in:
@@ -21,6 +21,7 @@ func NewService(resolver device.Resolver) lucifer3.ActiveService {
|
||||
|
||||
supportFlags: make(map[string]device.SupportFlags),
|
||||
colorFlags: make(map[string]device.ColorFlags),
|
||||
ctRanges: make(map[string]*[2]int),
|
||||
temperatures: make(map[string]float64),
|
||||
motions: make(map[string]float64),
|
||||
}
|
||||
@@ -39,8 +40,9 @@ type effectEnforcer struct {
|
||||
|
||||
started uint32
|
||||
|
||||
list []*effectEnforcerRun
|
||||
index map[string]*effectEnforcerRun
|
||||
list []*effectEnforcerRun
|
||||
index map[string]*effectEnforcerRun
|
||||
ctRanges map[string]*[2]int
|
||||
}
|
||||
|
||||
func (s *effectEnforcer) Active() bool {
|
||||
@@ -53,6 +55,7 @@ func (s *effectEnforcer) HandleEvent(bus *lucifer3.EventBus, event lucifer3.Even
|
||||
s.mu.Lock()
|
||||
colorFlags := s.colorFlags
|
||||
supportFlags := s.supportFlags
|
||||
ctRanges := s.ctRanges
|
||||
s.mu.Unlock()
|
||||
|
||||
colorFlags = gentools.CopyMap(colorFlags)
|
||||
@@ -60,9 +63,15 @@ func (s *effectEnforcer) HandleEvent(bus *lucifer3.EventBus, event lucifer3.Even
|
||||
colorFlags[event.ID] = event.ColorFlags
|
||||
supportFlags[event.ID] = event.SupportFlags
|
||||
|
||||
if event.ColorKelvinRange != nil {
|
||||
ctRanges = gentools.CopyMap(ctRanges)
|
||||
ctRanges[event.ID] = event.ColorKelvinRange
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.colorFlags = colorFlags
|
||||
s.supportFlags = supportFlags
|
||||
s.ctRanges = ctRanges
|
||||
s.mu.Unlock()
|
||||
|
||||
case events.DeviceReady:
|
||||
@@ -237,6 +246,7 @@ func (s *effectEnforcer) runLoop(bus *lucifer3.EventBus) {
|
||||
s.mu.Lock()
|
||||
colorFlags := s.colorFlags
|
||||
supportFlags := s.supportFlags
|
||||
ctRanges := s.ctRanges
|
||||
|
||||
for i, run := range s.list {
|
||||
if run.dead {
|
||||
@@ -307,11 +317,18 @@ func (s *effectEnforcer) runLoop(bus *lucifer3.EventBus) {
|
||||
state.Color = nil
|
||||
} else if state.Color != nil {
|
||||
cf := colorFlags[id]
|
||||
|
||||
invalid := (state.Color.K != nil && !cf.HasAll(device.CFlagKelvin)) ||
|
||||
(state.Color.XY != nil && !cf.HasAll(device.CFlagXY)) ||
|
||||
(state.Color.RGB != nil && !cf.HasAll(device.CFlagRGB)) ||
|
||||
(state.Color.HS != nil && !cf.HasAll(device.CFlagHS))
|
||||
|
||||
if state.Color.K != nil && cf.IsColor() && ctRanges[id] != nil {
|
||||
if *state.Color.K < ctRanges[id][0] || *state.Color.K >= ctRanges[id][1] {
|
||||
invalid = true
|
||||
}
|
||||
}
|
||||
|
||||
if invalid {
|
||||
var converted color.Color
|
||||
var ok bool
|
||||
|
||||
Reference in New Issue
Block a user