device ready handling.

This commit is contained in:
2022-08-21 16:28:22 +02:00
parent c3cc65618b
commit d1f42d932b
2 changed files with 18 additions and 21 deletions
+13 -1
View File
@@ -4,6 +4,7 @@ import (
lucifer3 "git.aiterp.net/lucifer3/server"
"git.aiterp.net/lucifer3/server/commands"
"git.aiterp.net/lucifer3/server/device"
"git.aiterp.net/lucifer3/server/events"
"sync"
"sync/atomic"
"time"
@@ -35,7 +36,18 @@ func (s *effectEnforcer) Active() bool {
return true
}
func (s *effectEnforcer) HandleEvent(_ *lucifer3.EventBus, _ lucifer3.Event) {}
func (s *effectEnforcer) HandleEvent(_ *lucifer3.EventBus, event lucifer3.Event) {
switch event := event.(type) {
case events.DeviceReady:
// If the device is managed by the effect enforcer, cause the effect to be
// re-ran.
s.mu.Lock()
if run, ok := s.index[event.ID]; ok && run.due.IsZero() {
run.due = time.Now()
}
s.mu.Unlock()
}
}
func (s *effectEnforcer) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command) {
switch command := command.(type) {