Skip to content

Commit

Permalink
fix inputfuncsourcelist
Browse files Browse the repository at this point in the history
  • Loading branch information
splattner committed Oct 30, 2023
1 parent a2bc586 commit f0c9cc0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/denonavr/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "reflect"
// Set an attribute and call entity Change function if changed
func (d *DenonAVR) SetAttribute(name string, value interface{}) {

changed := d.attributes[name] != nil && !reflect.DeepEqual(d.attributes[name], value)
changed := d.attributes[name] == nil || !reflect.DeepEqual(d.attributes[name], value)

d.attributes[name] = value

Expand Down
10 changes: 7 additions & 3 deletions pkg/denonavr/denonavr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package denonavr
import (
"encoding/xml"
"io"
"sort"
"time"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -201,12 +202,15 @@ func (d *DenonAVR) updateZoneStatusAndNotify(zone DenonZone) {
d.SetAttribute(zoneName+"SurroundMode", zoneStatus.SurrMode)

// We use the renamed input sources
var sourceList []string
inputFuncSelectList := d.GetZoneInputFuncList(zone)
// map[string]string are unorderen and range gives a different result on each run
inputList := make([]string, 0, len(inputFuncSelectList))
for _, renamedSource := range inputFuncSelectList {
sourceList = append(sourceList, renamedSource)
inputList = append(inputList, renamedSource)
}
d.SetAttribute(zoneName+"InputFuncList", sourceList)
// sort the slice by keys
sort.Strings(inputList)
d.SetAttribute(zoneName+"InputFuncList", inputList)

inputFuncSelect := zoneStatus.InputFuncSelect
// Rename Source with the SOURCE_MAPPING if necessary
Expand Down
22 changes: 3 additions & 19 deletions pkg/denonavr/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,14 @@ var PLAYING_SOURCES = append(append(append(NETAUDIO_SOURCES, NETAUDIO_SOURCES...

func (d *DenonAVR) GetZoneInputFuncList(zone DenonZone) map[string]string {

var inputFuncList map[string]string

switch zone {
case MainZone:
inputFuncList = d.getInputFuncList(d.zoneStatus[MainZone])
case Zone2:
inputFuncList = d.getInputFuncList(d.zoneStatus[Zone2])
case Zone3:
inputFuncList = d.getInputFuncList(d.zoneStatus[Zone3])
}

return inputFuncList
}

func (d *DenonAVR) getInputFuncList(zoneStatus DenonZoneStatus) map[string]string {

inputFuncList := make(map[string]string)

// Only add those not deleted
// Use renamed value
for i, input := range zoneStatus.InputFuncList {
for i, input := range d.zoneStatus[zone].InputFuncList {
// only the ones active or empty (== Online Music)
if zoneStatus.SourceDelete[i] == "USE" || zoneStatus.SourceDelete[i] == "" {
inputFuncList[input] = strings.TrimRight(zoneStatus.RenameSource[i], " ")
if d.zoneStatus[zone].SourceDelete[i] == "USE" || d.zoneStatus[zone].SourceDelete[i] == "" {
inputFuncList[input] = strings.TrimRight(d.zoneStatus[zone].RenameSource[i], " ")
}
}

Expand Down

0 comments on commit f0c9cc0

Please sign in to comment.