Merge branch 'beelzebub' of git.aiterp.net:Lucifer3/Server into beelzebub
This commit is contained in:
+8
-10
@@ -320,7 +320,7 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
|
||||
|
||||
// Handle power first
|
||||
if desired.Power != nil && active.Power != nil && *desired.Power != *active.Power {
|
||||
updates["light/"+*lightID] = ResourceUpdate{Power: gentools.Ptr(*active.Power)}
|
||||
updates["light/"+*lightID] = ResourceUpdate{Power: gentools.Ptr(*desired.Power)}
|
||||
|
||||
newActiveState := activeStates[id]
|
||||
newActiveState.Power = gentools.Ptr(*desired.Power)
|
||||
@@ -328,7 +328,7 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
|
||||
|
||||
continue
|
||||
}
|
||||
if active.Power != nil && *active.Power == false {
|
||||
if active.Power != nil && !*active.Power {
|
||||
// Don't do more with shut-off-light.
|
||||
continue
|
||||
}
|
||||
@@ -347,15 +347,13 @@ func (b *Bridge) makeCongruentLoop(ctx context.Context) {
|
||||
}
|
||||
|
||||
if dc.XY != nil {
|
||||
if ac.XY != nil {
|
||||
dist := math.Abs(ac.XY.X-dc.XY.X) + math.Abs(ac.XY.Y-dc.XY.Y)
|
||||
if dist > 0.0002 {
|
||||
update.ColorXY = gentools.Ptr(*dc.XY)
|
||||
updated = true
|
||||
}
|
||||
} else {
|
||||
newActiveState.Color = &color.Color{XY: gentools.Ptr(*dc.XY)}
|
||||
if ac.K != nil {
|
||||
ac.K = gentools.Ptr(1000000 / (1000000 / *ac.K))
|
||||
}
|
||||
|
||||
acXY, _ := ac.ToXY()
|
||||
dist := dc.XY.DistanceTo(*acXY.XY)
|
||||
if dist > 0.0002 {
|
||||
update.ColorXY = gentools.Ptr(*dc.XY)
|
||||
updated = true
|
||||
}
|
||||
|
||||
+19
-2
@@ -7,7 +7,6 @@ import (
|
||||
"git.aiterp.net/lucifer3/server/commands"
|
||||
"git.aiterp.net/lucifer3/server/events"
|
||||
"git.aiterp.net/lucifer3/server/internal/gentools"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -70,7 +69,12 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
||||
go func() {
|
||||
err := s.bridges[sub].SearchDevices(time.Second * 30)
|
||||
if err != nil {
|
||||
log.Println("Search failed:", err)
|
||||
bus.RunEvent(events.Log{
|
||||
ID: command.ID,
|
||||
Level: "error",
|
||||
Code: "search_failed",
|
||||
Message: "Could not search: " + err.Error(),
|
||||
})
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -92,6 +96,13 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
||||
s.bridges[sub] = bridge
|
||||
|
||||
go func() {
|
||||
bus.RunEvent(events.Log{
|
||||
ID: command.ID,
|
||||
Level: "info",
|
||||
Code: "connecting_device",
|
||||
Message: "Connecting to device...",
|
||||
})
|
||||
|
||||
for bridge.ctx.Err() == nil {
|
||||
ctx2, cancel2 := context.WithCancel(ctx)
|
||||
|
||||
@@ -102,6 +113,12 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
||||
ID: command.ID,
|
||||
Error: fmt.Sprintf("Run failed: %s", err),
|
||||
})
|
||||
bus.RunEvent(events.Log{
|
||||
ID: command.ID,
|
||||
Level: "error",
|
||||
Code: "connect_failed",
|
||||
Message: fmt.Sprintf("Could not connect device: %s", err),
|
||||
})
|
||||
}
|
||||
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user