scripting system, hue fixes and such
This commit is contained in:
@@ -13,10 +13,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewService(resolver device.Resolver, sceneMap device.SceneMap) lucifer3.ActiveService {
|
||||
func NewService(resolver device.Resolver) lucifer3.ActiveService {
|
||||
s := &effectEnforcer{
|
||||
resolver: resolver,
|
||||
sceneMap: sceneMap,
|
||||
list: make([]*effectEnforcerRun, 0, 16),
|
||||
index: make(map[string]*effectEnforcerRun, 8),
|
||||
|
||||
@@ -32,7 +31,6 @@ func NewService(resolver device.Resolver, sceneMap device.SceneMap) lucifer3.Act
|
||||
type effectEnforcer struct {
|
||||
mu sync.Mutex
|
||||
resolver device.Resolver
|
||||
sceneMap device.SceneMap
|
||||
|
||||
supportFlags map[string]device.SupportFlags
|
||||
colorFlags map[string]device.ColorFlags
|
||||
@@ -68,8 +66,7 @@ func (s *effectEnforcer) HandleEvent(bus *lucifer3.EventBus, event lucifer3.Even
|
||||
s.mu.Unlock()
|
||||
|
||||
case events.DeviceReady:
|
||||
// If the device is managed by the effect enforcer, cause the effect to be
|
||||
// re-ran.
|
||||
// If the device is managed by the effect enforcer, cause the effect to run again
|
||||
s.mu.Lock()
|
||||
if run, ok := s.index[event.ID]; ok {
|
||||
run.due = time.Now()
|
||||
@@ -98,11 +95,9 @@ func (s *effectEnforcer) HandleCommand(bus *lucifer3.EventBus, command lucifer3.
|
||||
switch command := command.(type) {
|
||||
case commands.Assign:
|
||||
pointers := s.resolver.Resolve(command.Match)
|
||||
allowedIDs := make([]string, 0, len(pointers))
|
||||
deviceIDs := make([]string, 0, len(pointers))
|
||||
for _, ptr := range pointers {
|
||||
if s.sceneMap.SceneID(ptr.ID) == nil {
|
||||
allowedIDs = append(allowedIDs, ptr.ID)
|
||||
}
|
||||
deviceIDs = append(deviceIDs, ptr.ID)
|
||||
}
|
||||
if len(pointers) == 0 {
|
||||
if command.ID != nil {
|
||||
@@ -135,13 +130,13 @@ func (s *effectEnforcer) HandleCommand(bus *lucifer3.EventBus, command lucifer3.
|
||||
match: command.Match,
|
||||
id: id,
|
||||
due: time.Now(),
|
||||
ids: allowedIDs,
|
||||
ids: deviceIDs,
|
||||
effect: command.Effect,
|
||||
}
|
||||
s.list = append(s.list, newRun)
|
||||
|
||||
// Switch over the indices.
|
||||
for _, id := range allowedIDs {
|
||||
for _, id := range deviceIDs {
|
||||
if oldRun := s.index[id]; oldRun != nil {
|
||||
oldRun.remove(id)
|
||||
}
|
||||
@@ -153,7 +148,7 @@ func (s *effectEnforcer) HandleCommand(bus *lucifer3.EventBus, command lucifer3.
|
||||
go s.runLoop(bus)
|
||||
}
|
||||
|
||||
for _, deviceID := range allowedIDs {
|
||||
for _, deviceID := range deviceIDs {
|
||||
bus.RunEvent(events.DeviceAssigned{
|
||||
DeviceID: deviceID,
|
||||
AssignmentID: gentools.Ptr(id),
|
||||
|
||||
Reference in New Issue
Block a user