|
|
package main
import ( lucifer3 "git.aiterp.net/lucifer3/server" "git.aiterp.net/lucifer3/server/device" "git.aiterp.net/lucifer3/server/events" "git.aiterp.net/lucifer3/server/internal/color" "git.aiterp.net/lucifer3/server/internal/gentools" "log" "time" )
func main() { bus := lucifer3.EventBus{}
bus.JoinCallback(func(event lucifer3.Event, sender lucifer3.ServiceID) bool { switch event := event.(type) { case events.HubConnected: log.Println("Callback got connect event") case events.DeviceAssignment: log.Println("Callback can see", len(event.IDs), "devices are being assigned") case events.DeviceRegister: log.Println("Callback should not see that", event.InternalID, "has got a new ID") case events.DeviceDesiredStateChange: log.Println("Callback saw", event.ID, "got a new state.") }
return true })
c := color.RGB{Red: 1, Green: 0.7, Blue: 0.25}.ToXY()
bus.Send(events.HubConnected{}, lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}, nil) bus.Send(events.DeviceAssignment{ IDs: []int64{1, 2, 3, 4, 5, 6, 7, 8, 9}, Version: 1, State: &device.State{ Power: gentools.Ptr(true), Temperature: nil, Intensity: nil, Color: &color.Color{XY: &c}, }, }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil) bus.Send(events.DeviceAssignment{ IDs: []int64{44, 45, 46, 47, 48, 49, 50, 51, 52, 53}, Version: 2, Effect: gentools.Ptr[int64](1044), }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil)
time.Sleep(time.Second / 2)
bus.Send(events.DeviceHardwareStateChange{ InternalID: "c68b310c-7fd6-47a4-ae11-d60d701769da", DeviceFlags: device.SFlagPower | device.SFlagIntensity, ColorFlags: 0, State: device.State{ Power: gentools.Ptr(true), Intensity: gentools.Ptr(0.75), }, }, lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}, nil)
time.Sleep(time.Second / 4)
bus.Send(events.DeviceRegister{ InternalID: "c68b310c-7fd6-47a4-ae11-d60d701769da", ID: 10, }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, &lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}) bus.Send(events.DeviceDesiredStateChange{ ID: 10, NewState: device.State{ Power: gentools.Ptr(true), Intensity: gentools.Ptr(0.75), }, }, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil)
time.Sleep(time.Second * 4) }
|