Browse Source

change scenes to use name as primary identifier.

beelzebub
Gisle Aune 2 years ago
parent
commit
ca5dc75a1c
  1. 4
      cmd/bustest/main.go
  2. 6
      commands/scene.go
  3. 2
      device/interfaces.go
  4. 8
      services/scenemap.go

4
cmd/bustest/main.go

@ -38,8 +38,8 @@ func main() {
} }
bus.RunCommand(commands.ReplaceScene{ bus.RunCommand(commands.ReplaceScene{
Match: "lucifer:name:Hex*",
SceneID: 7,
Match: "lucifer:name:Hex*",
SceneName: "Evening",
}) })
bus.RunCommand(commands.AddAlias{ bus.RunCommand(commands.AddAlias{

6
commands/scene.go

@ -5,12 +5,12 @@ import (
) )
type ReplaceScene struct { type ReplaceScene struct {
Match string `json:"match"`
SceneID int64 `json:"sceneId"`
Match string `json:"match"`
SceneName string `json:"sceneName"`
} }
func (c ReplaceScene) CommandDescription() string { func (c ReplaceScene) CommandDescription() string {
return fmt.Sprintf("ReplaceScene(%v, %d)", c.Match, c.SceneID)
return fmt.Sprintf("ReplaceScene(%v, %s)", c.Match, c.SceneName)
} }
type ClearScene struct { type ClearScene struct {

2
device/interfaces.go

@ -5,5 +5,5 @@ type Resolver interface {
} }
type SceneMap interface { type SceneMap interface {
SceneID(id string) *int64
SceneID(id string) *string
} }

8
services/scenemap.go

@ -11,7 +11,7 @@ import (
func NewSceneMap(resolver device.Resolver) *SceneMap { func NewSceneMap(resolver device.Resolver) *SceneMap {
return &SceneMap{ return &SceneMap{
resolver: resolver, resolver: resolver,
sceneMap: make(map[string]int64, 64),
sceneMap: make(map[string]string, 64),
} }
} }
@ -19,10 +19,10 @@ type SceneMap struct {
resolver device.Resolver resolver device.Resolver
mu sync.Mutex mu sync.Mutex
sceneMap map[string]int64
sceneMap map[string]string
} }
func (s *SceneMap) SceneID(id string) *int64 {
func (s *SceneMap) SceneID(id string) *string {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
@ -48,7 +48,7 @@ func (s *SceneMap) HandleCommand(_ *lucifer3.EventBus, command lucifer3.Command)
if len(matched) > 0 { if len(matched) > 0 {
s.mu.Lock() s.mu.Lock()
for _, ptr := range matched { for _, ptr := range matched {
s.sceneMap[ptr.ID] = command.SceneID
s.sceneMap[ptr.ID] = command.SceneName
} }
s.mu.Unlock() s.mu.Unlock()
} }

Loading…
Cancel
Save