|
@ -5,6 +5,7 @@ import ( |
|
|
"git.aiterp.net/lucifer/new-server/app/config" |
|
|
"git.aiterp.net/lucifer/new-server/app/config" |
|
|
"git.aiterp.net/lucifer/new-server/models" |
|
|
"git.aiterp.net/lucifer/new-server/models" |
|
|
"log" |
|
|
"log" |
|
|
|
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -40,6 +41,12 @@ func handleEvent(event models.Event) { |
|
|
event.AddPayload("minute", time.Now().In(loc).Format("04")) |
|
|
event.AddPayload("minute", time.Now().In(loc).Format("04")) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err := handleSpecial(event) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Printf("Special event handler error (%s): %v", event.Name, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if !X { |
|
|
if !X { |
|
|
log.Println("Unhandled event: " + event.Name) |
|
|
log.Println("Unhandled event: " + event.Name) |
|
|
return |
|
|
return |
|
@ -64,3 +71,28 @@ func handleEvent(event models.Event) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleSpecial(event models.Event) error { |
|
|
|
|
|
switch event.Name { |
|
|
|
|
|
case models.ENBridgeConnected: |
|
|
|
|
|
bridgeId, _ := strconv.Atoi(event.Payload["bridgeId"]) |
|
|
|
|
|
bridge, err := config.BridgeRepository().Find(ctx, bridgeId) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
devices, err := config.DeviceRepository().FetchByReference(ctx, models.RKBridgeID, event.Payload["bridgeId"]) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
driver, err := config.DriverProvider().Provide(bridge.Driver) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return driver.Publish(ctx, bridge, devices) |
|
|
|
|
|
default: |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
} |