Skip to content

Commit

Permalink
Merge pull request #30 from splattner/denon_mediatitleurl
Browse files Browse the repository at this point in the history
fix: get correct media title
  • Loading branch information
splattner authored Oct 4, 2023
2 parents f8737cd + 16ceec9 commit 5e531e2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/denonavr/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions pkg/denonavr/denonavr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -82,6 +83,7 @@ type DenonAVR struct {
mainZoneStatus DenonStatus
zone2Status DenonStatus
zone3Status DenonStatus
netAudioStatus DenonNetAudioStatus

attributes map[string]interface{}

Expand All @@ -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{}))

Expand Down Expand Up @@ -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?

Expand Down
30 changes: 30 additions & 0 deletions pkg/denonavr/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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...
Expand All @@ -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
}

0 comments on commit 5e531e2

Please sign in to comment.