Skip to content

Commit

Permalink
fix: use and set correct inputFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed Oct 19, 2023
1 parent b2d3b4b commit 56aba19
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 19 deletions.
15 changes: 3 additions & 12 deletions pkg/clients/denonavr/denonavrclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{}) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/denonavr/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
"time"

log "github.com/sirupsen/logrus"
)
Expand All @@ -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"

Expand Down
31 changes: 27 additions & 4 deletions pkg/denonavr/denonavr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 60 additions & 3 deletions pkg/denonavr/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

log "github.com/sirupsen/logrus"
"k8s.io/utils/strings/slices"
)

var SOURCE_MAPPING = map[string]string{
Expand All @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 56aba19

Please sign in to comment.