From ca5dc75a1cf84b5b104c9b2e83cf905281a0943c Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 19 Aug 2022 23:17:39 +0200 Subject: [PATCH] change scenes to use name as primary identifier. --- cmd/bustest/main.go | 4 ++-- commands/scene.go | 6 +++--- device/interfaces.go | 2 +- services/scenemap.go | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/bustest/main.go b/cmd/bustest/main.go index 1d235b7..4fc2447 100644 --- a/cmd/bustest/main.go +++ b/cmd/bustest/main.go @@ -38,8 +38,8 @@ func main() { } bus.RunCommand(commands.ReplaceScene{ - Match: "lucifer:name:Hex*", - SceneID: 7, + Match: "lucifer:name:Hex*", + SceneName: "Evening", }) bus.RunCommand(commands.AddAlias{ diff --git a/commands/scene.go b/commands/scene.go index 70ba6c6..5c4979a 100644 --- a/commands/scene.go +++ b/commands/scene.go @@ -5,12 +5,12 @@ import ( ) type ReplaceScene struct { - Match string `json:"match"` - SceneID int64 `json:"sceneId"` + Match string `json:"match"` + SceneName string `json:"sceneName"` } 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 { diff --git a/device/interfaces.go b/device/interfaces.go index 83c0eaa..15f640a 100644 --- a/device/interfaces.go +++ b/device/interfaces.go @@ -5,5 +5,5 @@ type Resolver interface { } type SceneMap interface { - SceneID(id string) *int64 + SceneID(id string) *string } diff --git a/services/scenemap.go b/services/scenemap.go index e35432c..ee3e1d4 100644 --- a/services/scenemap.go +++ b/services/scenemap.go @@ -11,7 +11,7 @@ import ( func NewSceneMap(resolver device.Resolver) *SceneMap { return &SceneMap{ resolver: resolver, - sceneMap: make(map[string]int64, 64), + sceneMap: make(map[string]string, 64), } } @@ -19,10 +19,10 @@ type SceneMap struct { resolver device.Resolver 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() defer s.mu.Unlock() @@ -48,7 +48,7 @@ func (s *SceneMap) HandleCommand(_ *lucifer3.EventBus, command lucifer3.Command) if len(matched) > 0 { s.mu.Lock() for _, ptr := range matched { - s.sceneMap[ptr.ID] = command.SceneID + s.sceneMap[ptr.ID] = command.SceneName } s.mu.Unlock() }