|
|
@ -2,6 +2,7 @@ package main |
|
|
|
|
|
|
|
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" |
|
|
|
"git.aiterp.net/lucifer3/server/internal/color" |
|
|
@ -13,65 +14,65 @@ import ( |
|
|
|
func main() { |
|
|
|
bus := lucifer3.EventBus{} |
|
|
|
|
|
|
|
bus.JoinCallback(func(event lucifer3.Event, sender lucifer3.ServiceID) bool { |
|
|
|
bus.JoinCallback(func(event lucifer3.Event) 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.") |
|
|
|
case events.Connected: |
|
|
|
log.Println("Callback got connect event for", event.Prefix) |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
bus.RunEvent(events.Connected{Prefix: "nanoleaf:10.80.1.11"}) |
|
|
|
|
|
|
|
time.Sleep(time.Second / 2) |
|
|
|
|
|
|
|
bus.Send(events.DeviceHardwareStateChange{ |
|
|
|
InternalID: "c68b310c-7fd6-47a4-ae11-d60d701769da", |
|
|
|
DeviceFlags: device.SFlagPower | device.SFlagIntensity, |
|
|
|
ColorFlags: 0, |
|
|
|
for _, id := range []string{"e28c", "67db", "f744", "d057", "73c1"} { |
|
|
|
bus.RunEvent(events.HardwareState{ |
|
|
|
DeviceID: "nanoleaf:10.80.1.11:" + id, |
|
|
|
SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity, |
|
|
|
ColorFlags: device.CFlagRGB, |
|
|
|
State: device.State{}, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
bus.RunCommand(commands.ReplaceScene{ |
|
|
|
IDs: []string{"nanoleaf:10.80.1.11:e28c", "nanoleaf:10.80.1.11:67db", "nanoleaf:10.80.1.11:f744", "nanoleaf:10.80.1.11:d057", "nanoleaf:10.80.1.11:73c1"}, |
|
|
|
SceneID: 7, |
|
|
|
}) |
|
|
|
for _, id := range []string{"nanoleaf:10.80.1.11:e28c", "nanoleaf:10.80.1.11:67db", "nanoleaf:10.80.1.11:f744", "nanoleaf:10.80.1.11:d057", "nanoleaf:10.80.1.11:73c1"} { |
|
|
|
bus.RunCommand(commands.SetState{ |
|
|
|
ID: id, |
|
|
|
State: device.State{ |
|
|
|
Power: gentools.Ptr(true), |
|
|
|
Intensity: gentools.Ptr(0.75), |
|
|
|
Color: gentools.Ptr(color.MustParse("xy:0.3209,0.1542")), |
|
|
|
}, |
|
|
|
}, lucifer3.ServiceID{Kind: lucifer3.SKDeviceHub, ID: 1}, nil) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
time.Sleep(time.Second / 4) |
|
|
|
time.Sleep(time.Second / 2) |
|
|
|
|
|
|
|
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{ |
|
|
|
bus.RunEvent(events.HardwareState{ |
|
|
|
DeviceID: "nanoleaf:10.80.1.11:40e5", |
|
|
|
SupportFlags: device.SFlagPower | device.SFlagColor | device.SFlagIntensity, |
|
|
|
ColorFlags: device.CFlagRGB, |
|
|
|
State: device.State{}, |
|
|
|
}) |
|
|
|
bus.RunCommand(commands.ReplaceScene{ |
|
|
|
IDs: []string{"nanoleaf:10.80.1.11:40e5", "nanoleaf:10.80.1.11:e28c", "nanoleaf:10.80.1.11:67db", "nanoleaf:10.80.1.11:f744", "nanoleaf:10.80.1.11:d057", "nanoleaf:10.80.1.11:73c1"}, |
|
|
|
SceneID: 7, |
|
|
|
}) |
|
|
|
bus.RunCommand(commands.SetState{ |
|
|
|
ID: "nanoleaf:10.80.1.11:40e5", |
|
|
|
State: device.State{ |
|
|
|
Power: gentools.Ptr(true), |
|
|
|
Intensity: gentools.Ptr(0.75), |
|
|
|
Color: gentools.Ptr(color.MustParse("xy:0.3209,0.1542")), |
|
|
|
}, |
|
|
|
}, lucifer3.ServiceID{Kind: lucifer3.SKSingleton, Name: "DeviceManager"}, nil) |
|
|
|
}) |
|
|
|
|
|
|
|
time.Sleep(time.Second / 4) |
|
|
|
|
|
|
|
time.Sleep(time.Second * 4) |
|
|
|
} |