misc
This commit is contained in:
+6
-7
@@ -25,7 +25,7 @@ func main() {
|
|||||||
|
|
||||||
bus.JoinCallback(func(event lucifer3.Event) bool {
|
bus.JoinCallback(func(event lucifer3.Event) bool {
|
||||||
switch event.(type) {
|
switch event.(type) {
|
||||||
case events.DevicesReady:
|
case events.DeviceReady:
|
||||||
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:2d0c", Alias: "lucifer:name:Hex 5"})
|
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:2d0c", Alias: "lucifer:name:Hex 5"})
|
||||||
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:542f", Alias: "lucifer:name:Hex 6"})
|
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:542f", Alias: "lucifer:name:Hex 6"})
|
||||||
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:e760", Alias: "lucifer:name:Hex 7"})
|
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:e760", Alias: "lucifer:name:Hex 7"})
|
||||||
@@ -39,7 +39,7 @@ func main() {
|
|||||||
Match: "nanoleaf:10.80.1.14:*",
|
Match: "nanoleaf:10.80.1.14:*",
|
||||||
Effect: effects.Pattern{
|
Effect: effects.Pattern{
|
||||||
States: []device.State{
|
States: []device.State{
|
||||||
{Power: p(true), Intensity: p(0.3), Color: p(color.MustParse("xy:0.22,0.18"))},
|
{Power: p(true), Intensity: p(1.0), Color: p(color.MustParse("xy:0.22,0.18"))},
|
||||||
{Power: p(true), Intensity: p(0.4), Color: p(color.MustParse("xy:0.22,0.18"))},
|
{Power: p(true), Intensity: p(0.4), Color: p(color.MustParse("xy:0.22,0.18"))},
|
||||||
{Power: p(true), Intensity: p(0.5), Color: p(color.MustParse("xy:0.22,0.18"))},
|
{Power: p(true), Intensity: p(0.5), Color: p(color.MustParse("xy:0.22,0.18"))},
|
||||||
},
|
},
|
||||||
@@ -47,16 +47,15 @@ func main() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 1)
|
||||||
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:*", Alias: "lucifer:tag:Magic Lamps"})
|
bus.RunCommand(commands.AddAlias{Match: "nanoleaf:10.80.1.14:*", Alias: "lucifer:tag:Magic Lamps"})
|
||||||
bus.RunCommand(commands.Assign{
|
bus.RunCommand(commands.Assign{
|
||||||
Match: "lucifer:tag:Magic Lamps",
|
Match: "lucifer:tag:Magic Lamps",
|
||||||
Effect: effects.Gradient{
|
Effect: effects.Pattern{
|
||||||
States: []device.State{
|
States: []device.State{
|
||||||
{Power: p(true), Intensity: p(0.5), Color: p(color.MustParse("xy:0.22,0.18"))},
|
{Power: p(true), Intensity: p(1.0), Color: p(color.MustParse("hs:0,0.9"))},
|
||||||
{Power: p(true), Intensity: p(0.8), Color: p(color.MustParse("xy:0.22,0.18"))},
|
{Power: p(true), Intensity: p(0.7), Color: p(color.MustParse("hs:100,0.8"))},
|
||||||
},
|
},
|
||||||
Interpolate: true,
|
|
||||||
AnimationMS: 500,
|
AnimationMS: 500,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ func (e Gradient) State(index, length, round int) device.State {
|
|||||||
if e.Reverse {
|
if e.Reverse {
|
||||||
round = -round
|
round = -round
|
||||||
}
|
}
|
||||||
walkedIndex := ((length + index) - round) % length
|
walkedIndex := ((length + index) - (round % length)) % length
|
||||||
|
|
||||||
return gradientState(e.States, e.Interpolate, walkedIndex, length)
|
return gradientState(e.States, e.Interpolate, walkedIndex, length)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -52,13 +52,13 @@ func (e HardwareMetadata) EventDescription() string {
|
|||||||
return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
|
return fmt.Sprintf("HardwareMetadata(id:%s, icon:%s, ...)", e.ID, e.Icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DevicesReady is triggered to indicate that all hardware states have been pushed to the bus ahead of this event.
|
// DeviceReady is triggered to indicate that all hardware states have been pushed to the bus ahead of this event.
|
||||||
type DevicesReady struct {
|
type DeviceReady struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d DevicesReady) EventDescription() string {
|
func (d DeviceReady) EventDescription() string {
|
||||||
return fmt.Sprintf("DevicesReady(id:%s)", d.ID)
|
return fmt.Sprintf("DeviceReady(id:%s)", d.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DevicesUnreachable struct {
|
type DevicesUnreachable struct {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (s *effectEnforcer) runLoop(bus *lucifer3.EventBus) {
|
|||||||
deleteList := make([]int, 0, 8)
|
deleteList := make([]int, 0, 8)
|
||||||
batch := make(commands.SetStateBatch, 64)
|
batch := make(commands.SetStateBatch, 64)
|
||||||
|
|
||||||
for now := range time.NewTicker(time.Millisecond * 100).C {
|
for now := range time.NewTicker(time.Millisecond * 25).C {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
for i, run := range s.list {
|
for i, run := range s.list {
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -79,18 +79,16 @@ func (b *bridge) HardwareEvents() []lucifer3.Event {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(results, events.DevicesReady{
|
return results
|
||||||
ID: fmt.Sprintf("nanoleaf:%s", b.host),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bridge) Refresh(ctx context.Context) (bool, error) {
|
func (b *bridge) Refresh(ctx context.Context) ([]string, error) {
|
||||||
overview, err := b.Overview(ctx)
|
overview, err := b.Overview(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
changed := false
|
newIDs := make([]string, 0, 0)
|
||||||
|
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
PanelLoop:
|
PanelLoop:
|
||||||
@@ -110,13 +108,13 @@ PanelLoop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changed = true
|
|
||||||
|
|
||||||
idBytes := [2]byte{0, 0}
|
idBytes := [2]byte{0, 0}
|
||||||
binary.BigEndian.PutUint16(idBytes[:], panelInfo.PanelID)
|
binary.BigEndian.PutUint16(idBytes[:], panelInfo.PanelID)
|
||||||
hexID := hex.EncodeToString(idBytes[:])
|
hexID := hex.EncodeToString(idBytes[:])
|
||||||
fullID := fmt.Sprintf("nanoleaf:%s:%s", b.host, hexID)
|
fullID := fmt.Sprintf("nanoleaf:%s:%s", b.host, hexID)
|
||||||
|
|
||||||
|
newIDs = append(newIDs, fullID)
|
||||||
|
|
||||||
b.panelIDMap[panelInfo.PanelID] = fullID
|
b.panelIDMap[panelInfo.PanelID] = fullID
|
||||||
b.panels = append(b.panels, &panel{
|
b.panels = append(b.panels, &panel{
|
||||||
ID: panelInfo.PanelID,
|
ID: panelInfo.PanelID,
|
||||||
@@ -133,7 +131,7 @@ PanelLoop:
|
|||||||
}
|
}
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
|
|
||||||
return changed, nil
|
return newIDs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bridge) Overview(ctx context.Context) (*Overview, error) {
|
func (b *bridge) Overview(ctx context.Context) (*Overview, error) {
|
||||||
@@ -213,7 +211,7 @@ func (b *bridge) Run(ctx context.Context, bus *lucifer3.EventBus) error {
|
|||||||
Prefix: fmt.Sprintf("nanoleaf:%s", b.host),
|
Prefix: fmt.Sprintf("nanoleaf:%s", b.host),
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err = b.Refresh(ctx)
|
newIDs, err := b.Refresh(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -261,6 +259,10 @@ func (b *bridge) Run(ctx context.Context, bus *lucifer3.EventBus) error {
|
|||||||
for _, event := range b.HardwareEvents() {
|
for _, event := range b.HardwareEvents() {
|
||||||
bus.RunEvent(event)
|
bus.RunEvent(event)
|
||||||
}
|
}
|
||||||
|
for _, id := range newIDs {
|
||||||
|
bus.RunEvent(events.DeviceReady{ID: id})
|
||||||
|
}
|
||||||
|
bus.RunEvent(events.DeviceReady{ID: fmt.Sprintf("nanoleaf:%s", b.host)})
|
||||||
|
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
|||||||
if sub, ok := command.Matches("nanoleaf"); ok {
|
if sub, ok := command.Matches("nanoleaf"); ok {
|
||||||
if s.bridges[sub] != nil {
|
if s.bridges[sub] != nil {
|
||||||
go func(bridge *bridge) {
|
go func(bridge *bridge) {
|
||||||
changed, err := bridge.Refresh(context.Background())
|
newIDs, err := bridge.Refresh(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
bus.RunEvent(events.DeviceFailed{
|
bus.RunEvent(events.DeviceFailed{
|
||||||
ID: command.ID,
|
ID: command.ID,
|
||||||
@@ -52,10 +52,13 @@ func (s *service) HandleCommand(bus *lucifer3.EventBus, command lucifer3.Command
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if changed {
|
if len(newIDs) > 0 {
|
||||||
for _, event := range bridge.HardwareEvents() {
|
for _, event := range bridge.HardwareEvents() {
|
||||||
bus.RunEvent(event)
|
bus.RunEvent(event)
|
||||||
}
|
}
|
||||||
|
for _, id := range newIDs {
|
||||||
|
bus.RunEvent(events.DeviceReady{ID: id})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}(s.bridges[sub])
|
}(s.bridges[sub])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user