From 56aba195d5ffdab93bd56d91f8586adfdb360fa5 Mon Sep 17 00:00:00 2001 From: Sebastian Plattner Date: Thu, 19 Oct 2023 19:04:45 +0200 Subject: [PATCH] fix: use and set correct inputFunc --- pkg/clients/denonavr/denonavrclient.go | 15 ++---- pkg/denonavr/commands.go | 4 ++ pkg/denonavr/denonavr.go | 31 +++++++++++-- pkg/denonavr/source.go | 63 ++++++++++++++++++++++++-- 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/pkg/clients/denonavr/denonavrclient.go b/pkg/clients/denonavr/denonavrclient.go index d7b7919..230d4e1 100644 --- a/pkg/clients/denonavr/denonavrclient.go +++ b/pkg/clients/denonavr/denonavrclient.go @@ -53,7 +53,7 @@ func NewDenonAVRClient(i *integration.Integration) *DenonAVRClient { Name: integration.LanguageText{ En: "Denon AVR", }, - Version: "0.2.3", + Version: "0.2.4", SetupDataSchema: integration.SetupDataSchema{ Title: integration.LanguageText{ En: "Configuration", @@ -168,20 +168,11 @@ func (c *DenonAVRClient) configureDenon() { }) c.denon.AddHandleEntityChangeFunc("MainZoneInputFuncList", func(value interface{}) { - var sourceList []string - mainZoneInputFuncSelectList := c.denon.GetZoneInputFuncList(denonavr.MainZone) - for _, renamedSource := range mainZoneInputFuncSelectList { - sourceList = append(sourceList, renamedSource) - } - - c.mediaPlayer.SetAttribute(entities.SourceListMediaPlayerEntityAttribute, sourceList) + c.mediaPlayer.SetAttribute(entities.SourceListMediaPlayerEntityAttribute, value.([]string)) }) c.denon.AddHandleEntityChangeFunc("MainZoneInputFuncSelect", func(value interface{}) { - - // We use the renamed Name - mainZoneInputFuncSelectList := c.denon.GetZoneInputFuncList(denonavr.MainZone) - c.mediaPlayer.SetAttribute(entities.SourceMediaPlayerEntityAttribute, mainZoneInputFuncSelectList[value.(string)]) + c.mediaPlayer.SetAttribute(entities.SourceMediaPlayerEntityAttribute, value.(string)) }) c.denon.AddHandleEntityChangeFunc("MainZoneSurroundMode", func(value interface{}) { diff --git a/pkg/denonavr/commands.go b/pkg/denonavr/commands.go index f1f6ce8..ae16662 100644 --- a/pkg/denonavr/commands.go +++ b/pkg/denonavr/commands.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/url" + "time" log "github.com/sirupsen/logrus" ) @@ -21,6 +22,9 @@ func (d *DenonAVR) sendCommandToDevice(denonCommandType DenonCommand, command st return req.StatusCode, fmt.Errorf("Error sending command: %w", err) } + // Wait befor get an update + time.Sleep(1 * time.Second) + // Trigger a updata data, handeld in the Listen Loop d.updateTrigger <- "update" diff --git a/pkg/denonavr/denonavr.go b/pkg/denonavr/denonavr.go index 9dedabd..1a9c2cc 100644 --- a/pkg/denonavr/denonavr.go +++ b/pkg/denonavr/denonavr.go @@ -233,12 +233,35 @@ func (d *DenonAVR) updateAndNotify() { d.callEntityChangeFunction("Zone3Mute", d.zone3Status.Mute) } - // Video Select + // Input Func if !reflect.DeepEqual(oldMainZoneStatus.InputFuncList, d.mainZoneStatus.InputFuncList) { - d.callEntityChangeFunction("MainZoneInputFuncList", d.mainZoneData.VideoSelectList) + + var sourceList []string + mainZoneInputFuncSelectList := d.GetZoneInputFuncList(MainZone) + for _, renamedSource := range mainZoneInputFuncSelectList { + sourceList = append(sourceList, renamedSource) + } + + d.callEntityChangeFunction("MainZoneInputFuncList", sourceList) } - if oldMainZoneData.VideoSelect != d.mainZoneData.VideoSelect { - d.callEntityChangeFunction("MainZoneInputFuncSelect", d.mainZoneData.VideoSelect) + if oldMainZoneStatus.InputFuncSelect != d.mainZoneStatus.InputFuncSelect { + + inputFuncSelect := d.mainZoneStatus.InputFuncSelect + + // Rename Source with the SOURCE_MAPPING if necessary + for source, origin := range SOURCE_MAPPING { + if origin == d.mainZoneStatus.InputFuncSelect { + inputFuncSelect = source + break + } + } + // And then custom renames + mainZoneInputFuncSelectList := d.GetZoneInputFuncList(MainZone) + if mainZoneInputFuncSelectList[inputFuncSelect] != "" { + inputFuncSelect = mainZoneInputFuncSelectList[inputFuncSelect] + } + + d.callEntityChangeFunction("MainZoneInputFuncSelect", inputFuncSelect) } // Surround Mode diff --git a/pkg/denonavr/source.go b/pkg/denonavr/source.go index 151981b..5bbfcbf 100644 --- a/pkg/denonavr/source.go +++ b/pkg/denonavr/source.go @@ -4,6 +4,7 @@ import ( "strings" log "github.com/sirupsen/logrus" + "k8s.io/utils/strings/slices" ) var SOURCE_MAPPING = map[string]string{ @@ -14,12 +15,64 @@ var SOURCE_MAPPING = map[string]string{ "CBL/SAT": "SAT/CBL", "NETWORK": "NET", "Media Player": "MPLAY", - "AUX1": "AUX1", + "AUX": "AUX1", "Tuner": "TUNER", "FM": "TUNER", "SpotifyConnect": "Spotify Connect", } +var CHANGE_INPUT_MAPPING = map[string]string{ + "Favorites": "FAVORITES", + "Flickr": "FLICKR", + "Internet Radio": "IRADIO", + "Media Server": "SERVER", + "Online Music": "NET", + "Spotify": "SPOTIFY", +} + +var TELNET_SOURCES = []string{ + "CD", + "PHONO", + "TUNER", + "DVD", + "BD", + "TV", + "SAT/CBL", + "MPLAY", + "GAME", + "HDRADIO", + "NET", + "PANDORA", + "SIRIUSXM", + "SOURCE", + "LASTFM", + "FLICKR", + "IRADIO", + "IRP", + "SERVER", + "FAVORITES", + "AUX1", + "AUX2", + "AUX3", + "AUX4", + "AUX5", + "AUX6", + "AUX7", + "BT", + "USB/IPOD", + "USB DIRECT", + "IPOD DIRECT", +} + +var TELNET_MAPPING = map[string]string{ + "FAVORITES": "Favorites", + "FLICKR": "Flickr", + "IRADIO": "Internet Radio", + "IRP": "Internet Radio", + "SERVER": "Media Server", + "SPOTIFY": "Spotify", +} + var NETAUDIO_SOURCES = []string{ "AirPlay", "Online Music", @@ -95,10 +148,14 @@ func (d *DenonAVR) SetSelectSourceMainZone(source string) int { selectedSource = sourceOrigin break } - } + if SOURCE_MAPPING[selectedSource] != "" { - status, _ := d.sendCommandToDevice(DenonCommandSelectInput, SOURCE_MAPPING[selectedSource]) + selectedSource = SOURCE_MAPPING[selectedSource] + } + + if slices.Contains(TELNET_SOURCES, selectedSource) { + status, _ := d.sendCommandToDevice(DenonCommandSelectInput, selectedSource) return status }