|
@ -7,7 +7,6 @@ import ( |
|
|
"git.aiterp.net/lucifer3/server/commands" |
|
|
"git.aiterp.net/lucifer3/server/commands" |
|
|
"git.aiterp.net/lucifer3/server/events" |
|
|
"git.aiterp.net/lucifer3/server/events" |
|
|
"git.aiterp.net/lucifer3/server/internal/gentools" |
|
|
"git.aiterp.net/lucifer3/server/internal/gentools" |
|
|
"log" |
|
|
|
|
|
"sync" |
|
|
"sync" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
@ -70,7 +69,12 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command |
|
|
go func() { |
|
|
go func() { |
|
|
err := s.bridges[sub].SearchDevices(time.Second * 30) |
|
|
err := s.bridges[sub].SearchDevices(time.Second * 30) |
|
|
if err != nil { |
|
|
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 |
|
|
s.bridges[sub] = bridge |
|
|
|
|
|
|
|
|
go func() { |
|
|
go func() { |
|
|
|
|
|
bus.RunEvent(events.Log{ |
|
|
|
|
|
ID: command.ID, |
|
|
|
|
|
Level: "info", |
|
|
|
|
|
Code: "connecting_device", |
|
|
|
|
|
Message: "Connecting to device...", |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
for bridge.ctx.Err() == nil { |
|
|
for bridge.ctx.Err() == nil { |
|
|
ctx2, cancel2 := context.WithCancel(ctx) |
|
|
ctx2, cancel2 := context.WithCancel(ctx) |
|
|
|
|
|
|
|
@ -102,6 +113,12 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command |
|
|
ID: command.ID, |
|
|
ID: command.ID, |
|
|
Error: fmt.Sprintf("Run failed: %s", err), |
|
|
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 { |
|
|
select { |
|
|