diff --git a/pkg/denonavr/attributes.go b/pkg/denonavr/attributes.go index 2a5ed2c..0649e4c 100644 --- a/pkg/denonavr/attributes.go +++ b/pkg/denonavr/attributes.go @@ -10,7 +10,7 @@ import ( // Set an attribute and return true uf the attributed has changed func (d *DenonAVR) SetAttribute(name string, value interface{}) { - changed := d.attributes[name] != nil && d.attributes[name] == value + changed := d.attributes[name] != nil && d.attributes[name] != value d.attributes[name] = value @@ -29,8 +29,7 @@ func (d *DenonAVR) getMediaTitle() string { if d.IsOn() { if slices.Contains(PLAYING_SOURCES, d.mainZoneData.InputFuncSelect) { // This is a source that is playing audio - // fot the moment, also set this to the input func - media_title = d.mainZoneData.InputFuncSelect + media_title = d.netAudioStatus.SzLine[1] } else { // Not a playing source media_title = d.mainZoneData.InputFuncSelect diff --git a/pkg/denonavr/denonavr.go b/pkg/denonavr/denonavr.go index bc2d8db..a49f49c 100644 --- a/pkg/denonavr/denonavr.go +++ b/pkg/denonavr/denonavr.go @@ -35,11 +35,12 @@ const ( ) const ( - STATUS_URL string = "/goform/formMainZone_MainZoneXmlStatus.xml" - STATUS_Z2_URL string = "/goform/formZone2_Zone2XmlStatus.xml" - STATUS_Z3_URL string = "/goform/formZone3_Zone3XmlStatus.xml" - MAINZONE_URL string = "/goform/formMainZone_MainZoneXml.xml" - COMMAND_URL string = "/goform/formiPhoneAppDirect.xml" + STATUS_URL string = "/goform/formMainZone_MainZoneXmlStatus.xml" + STATUS_Z2_URL string = "/goform/formZone2_Zone2XmlStatus.xml" + STATUS_Z3_URL string = "/goform/formZone3_Zone3XmlStatus.xml" + MAINZONE_URL string = "/goform/formMainZone_MainZoneXml.xml" + COMMAND_URL string = "/goform/formiPhoneAppDirect.xml" + NET_AUDIO_STATUR_URL string = "/goform/formNetAudio_StatusXml.xml" ) type DenonXML struct { @@ -82,6 +83,7 @@ type DenonAVR struct { mainZoneStatus DenonStatus zone2Status DenonStatus zone3Status DenonStatus + netAudioStatus DenonNetAudioStatus attributes map[string]interface{} @@ -101,6 +103,7 @@ func NewDenonAVR(host string) *DenonAVR { denonavr.mainZoneStatus = DenonStatus{} denonavr.zone2Status = DenonStatus{} denonavr.zone3Status = DenonStatus{} + denonavr.netAudioStatus = DenonNetAudioStatus{} denonavr.entityChangedFunction = make(map[string][]func(interface{})) @@ -180,6 +183,7 @@ func (d *DenonAVR) updateAndNotify() { d.getZoneStatus(MainZone) d.getZoneStatus(Zone2) d.getZoneStatus(Zone3) + d.getNetAudioStatus() // TODO: make the following part nicer? diff --git a/pkg/denonavr/status.go b/pkg/denonavr/status.go index ee1b8b1..f8b8f20 100644 --- a/pkg/denonavr/status.go +++ b/pkg/denonavr/status.go @@ -24,6 +24,11 @@ type DenonStatus struct { Model string `xml:"Model>value"` } +type DenonNetAudioStatus struct { + XMLName xml.Name `xml:"item"` + SzLine []string `xml:"szLine>value"` +} + func (d *DenonAVR) getZoneStatus(zone DenonZone) { switch zone { case MainZone: @@ -42,6 +47,11 @@ func (d *DenonAVR) getZoneStatus(zone DenonZone) { } +func (d *DenonAVR) getNetAudioStatus() { + url := "http://" + d.Host + NET_AUDIO_STATUR_URL + d.netAudioStatus = d.getNetAudioStatusFromDevice(url) +} + // Return the Status from a Zone func (d *DenonAVR) getZoneStatusFromDevice(url string) DenonStatus { status := DenonStatus{} // Somehow the values in the array are added instead of replaced. Not sure if this is the solution, but it works... @@ -61,3 +71,23 @@ func (d *DenonAVR) getZoneStatusFromDevice(url string) DenonStatus { return status } + +// Return the Status from a Zone +func (d *DenonAVR) getNetAudioStatusFromDevice(url string) DenonNetAudioStatus { + status := DenonNetAudioStatus{} // Somehow the values in the array are added instead of replaced. Not sure if this is the solution, but it works... + resp, err := http.Get(url) + if err != nil { + log.Fatalln(err) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.WithError(err).Error("Cannot read response body") + } + + if err := xml.Unmarshal(body, &status); err != nil { + log.WithError(err).Info("Could not unmarshall") + } + + return status +}