ol-iver / denonavr

Automation Library for Denon AVR receivers.
MIT License
174 stars 66 forks source link

Sound mode support #38

Closed starkillerOG closed 6 years ago

starkillerOG commented 6 years ago

I am trying to get Sound mode supported for the denonavr platform in Home Assistant. I already have my code working and I have tested it. My pull request is in: https://github.com/home-assistant/home-assistant/pull/11764#issuecomment-359214775

However I implemented my code directly in the denonavr component of HA, but it would be way nicer to have the parsing code in this denonavr library.

Could Sound Mode be supported in this denonavr library.

The relevant code I would like to implement in this library is:

Setup:

sound_mode_dict = OrderedDict([('MUSIC', 'PLII MUSIC'),
                                       ('MOVIE', 'PLII MOVIE'),
                                       ('GAME', 'PLII GAME'),
                                       ('PURE DIRECT', 'DIRECT'),
                                       ('AUTO', 'None'),
                                       ('DOLBY DIGITAL', 'DOLBY DIGITAL'),
                                       ('MCH STEREO', 'MULTI CH STEREO'),
('STEREO', 'STEREO')])

self._sound_mode_list = list(sound_mode_dict)
self._sound_mode_dict = sound_mode_dict

The key-value structure in the sound_mode_dict is needed because the commands to set an sound mode and the reported sound mode are diffrent. This structure matches the reported sound mode with the commands to set a sound mode. The key needs to be identical with the command to set a specific sound mode and the corresponding value needs to be the sound mode as reported by the AVR. Of course it would be awesom if this information could be obtained from the AVR and it schould be possible because the list is also displayed in the official phone application, but I could not figure out how to do it.

Get the current sound mode and parse the data:

        if self._sound_mode_support:
            try:
                url = ('http://' + str(self._host) +
                       '/goform/formMainZone_MainZoneXml.xml')
                xml_data = urllib.request.urlopen(url)
            except urllib.error.URLError:
                err = "Denon receiver failed to get sound mode, URL-Error"
                _LOGGER.error(err)
                return
            parsed_data = ET.parse(xml_data).getroot()
            sound_mode_raw = parsed_data.find('selectSurround/value')
            sound_mode_raw = sound_mode_raw.text.rstrip()
            try:
                mode_list = list(self._sound_mode_dict.values())
                mode_index = mode_list.index(sound_mode_raw.upper())
                sound_mode = list(self._sound_mode_dict.keys())[mode_index]
                self._current_sound_mode = sound_mode
            except ValueError:
self._current_sound_mode = sound_mode_raw

Set the sound mode to some value:

    def select_sound_mode(self, sound_mode):
        """Select sound mode."""
        url = ('http://' + str(self._host) +
               '/MainZone/index.put.asp?cmd0=PutSurroundMode%2F'
               + sound_mode.upper().replace(" ", "+"))
        urllib.request.urlopen(url)
return sound_mode

The complete code can be vieuwed in my PR: https://github.com/starkillerOG/home-assistant/blob/soundModeSupport/homeassistant/components/media_player/denonavr.py

Does someone have time to implement this in this library?

starkillerOG commented 6 years ago

I just figured out that information about which sound modes are supported can be found in: "http://" + DEVICE_IP + "/goform/Deviceinfo.xml"

starkillerOG commented 6 years ago

I als found these XML forms: http:///goform/formMainZone_MainZoneXml.xml http:///goform/formMainZone_MainZoneXmlStatus.xml http:///goform/formMainZone_MainZoneXmlStatusLite.xml http:///goform/formNetAudio_StatusXml.xml

starkillerOG commented 6 years ago

@scarface-4711 Is this easy to integrate in the denonavr library? My pull request for Home Assistant is waiting until this can be integrated in this denonavr library...

cajuncoding commented 6 years ago

Fyi, the denonavr library is not compatible with the (2017 and newer) X series of receivers; we have an open ticket here to try and get better support with @scarface-4711 since October of last year.

In case you find it useful we've done a-lot of research on the commands that work correctly with X series receivers on this other ticket thread.

Long story short, the current library is not compatible with the newer X series receivers and much of the core functionality needs to be rewrtten in denonavr to work with the changes that Denon introduced.

So I would hope any enhancements might also include better/proper support for newer receivers.

ol-iver commented 6 years ago

Hi @starkillerOG, the function itself does not look to complicated. But the mapping list is going to be quite long and not a 1:1 relationship in every case. Especially DOLBY DIGITAL and DTS SURROUND groups have many different mapping entries. At my AVR-X4100W the 'selectSurround/value' is DTS Neo:X Cinema atm and I found this value with a different spelling in the IP protocol manual. The list has more than 100 entries and that's only for my receiver. It would be a mess to type figure out all of the in the correct spelling manually. Do you have an idea where we could get those mappings in a more reliable way?

starkillerOG commented 6 years ago

@scarface-4711 I have been struggeling with the same problem, because the mapping is of course not an ideal solution. I have tryed searching through the diffrent xml files of my Marantz but all of them list the "current sound mode" as something like "PLII MUSIC" etc. And the only command to get it to that state I found was "MUSIC" withouth the PLII, this diffrence in spelling is verry verry inconvineant.

I did manage to find a list of the supported sound mode commands in the "http://" + DEVICE_IP + "/goform/Deviceinfo.xml". The following code is present there (part of the full xml):

<Category>5</Category>
<IconId>212</IconId>
<DispName>DIRECT</DispName>
<FuncName>DIRECT</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>212</IconId>
<DispName>STEREO</DispName>
<FuncName>STEREO</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>213</IconId>
<DispName>PURE DIRECT</DispName>
<FuncName>PURE DIRECT</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>214</IconId>
<DispName>DOLBY DIGITAL</DispName>
<FuncName>DOLBY DIGITAL</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>214</IconId>
<DispName>DTS SURROUND</DispName>
<FuncName>DTS SURROUND</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>224</IconId>
<DispName>AUTO</DispName>
<FuncName>AUTO</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>215</IconId>
<DispName>MULTI CH STEREO</DispName>
<FuncName>MULTI CH STEREO</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>226</IconId>
<DispName>VIRTUAL</DispName>
<FuncName>VIRTUAL</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>220</IconId>
<DispName>MOVIE</DispName>
<FuncName>MOVIE</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>221</IconId>
<DispName>MUSIC</DispName>
<FuncName>MUSIC</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>222</IconId>
<DispName>GAME</DispName>
<FuncName>GAME</FuncName>
</Shortcut>
<Shortcut>
<Category>5</Category>
<IconId>223</IconId>
<DispName>PURE</DispName>
<FuncName>PURE</FuncName>
</Shortcut>

The good thing is that this contains all the supported sound mode commands, but suprise suprise, this is an a third way of spelling, so not all commands match exactly with the correct spelling. for example the "MUSIC" is in the correct spelling for the command, but the "MULTI CH STEREO" is actually the spelling of the status, the command schould be "MCH STEREO". I checked but my receiver does not react to the command "MULTI CH STEREO", only to "MCH STEREO".

To be short, the mapping is really, really anoying, but as far as I can see it is the only option.

ol-iver commented 6 years ago

In my Deviceinfo.xml there is the SurroundMode section which sounds more correct than the "Shortcut" section. Do you have the same one?

<SurroundMode>
<Control>1</Control>
<DispName>Sound Mode</DispName>
<GroupList>
<Group>
<GroupName>Direct/Stereo</GroupName>
</Group>
<Group>
<GroupName>Pure Direct</GroupName>
</Group>
<Group>
<GroupName>Standard</GroupName>
</Group>
<Group>
<GroupName>Auto</GroupName>
</Group>
<Group>
<GroupName>DSP Simulation</GroupName>
</Group>
</GroupList>
<List>
<Mode>
<IconId>212</IconId>
<GroupName>Direct/Stereo</GroupName>
<Name>Direct</Name>
</Mode>
<Mode>
<IconId>212</IconId>
<GroupName>Direct/Stereo</GroupName>
<Name>Stereo</Name>
</Mode>
<Mode>
<IconId>213</IconId>
<GroupName>Pure Direct</GroupName>
<Name>Pure Direct</Name>
</Mode>
<Mode>
<IconId>214</IconId>
<GroupName>Standard</GroupName>
<Name>Dolby Digital</Name>
</Mode>
<Mode>
<IconId>214</IconId>
<GroupName>Standard</GroupName>
<Name>DTS Surround</Name>
</Mode>
<Mode>
<IconId>224</IconId>
<GroupName>Auto</GroupName>
<Name>Auto</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Multi Ch Stereo</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Rock Arena</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Jazz Club</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Mono Movie</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Video Game</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Matrix</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>Virtual</Name>
</Mode>
</List>
<Functions>
<ChangeSurroundMode>1</ChangeSurroundMode>
</Functions>
<ShortcutControl>1</ShortcutControl>
</SurroundMode>

The bigger problem is probably the mapping. I found this list I mentioned before. All entries of the next list a potentially mapped to DOLBY DIGITAL. The list for DTS SURROUND has about the same size and some entries appear in both lists. I'll play around with my receiver switching through all values to see if I find something. Otherwise the mapping would become huge. Unfortunately the Denon/Marantz are not well designed. There are strange value mappings everywhere...

DOLBY PRO LOGIC
DOLBY PL2 C
DOLBY PL2 M
DOLBY PL2 G
DOLBY PL2X C
DOLBY PL2X M
DOLBY PL2X G
DOLBY PL2Z H
DOLBY SURROUND
DOLBY ATMOS
DOLBY DIGITAL
DOLBY D EX
DOLBY D+PL2X C
DOLBY D+PL2X M
DOLBY D+PL2Z H
DOLBY D+DS
DOLBY D+NEO:X C
DOLBY D+NEO:X M
DOLBY D+NEO:X G
DTS SURROUND
DTS ES DSCRT6.1
DTS ES MTRX6.1
DTS+PL2X C
DTS+PL2X M
DTS+PL2Z H
DTS+DS
DTS96/24
DTS96 ES MTRX
DTS+NEO:6
DTS+NEO:X C
DTS+NEO:X M
DTS+NEO:X G
MULTI CH IN
M CH IN+DOLBY EX
M CH IN+PL2X C
M CH IN+PL2X M
M CH IN+PL2Z H
M CH IN+DS
MULTI CH IN 7.1
M CH IN+NEO:X C
M CH IN+NEO:X M
M CH IN+NEO:X G
DOLBY D+
DOLBY D+ +EX
DOLBY D+ +PL2X C
DOLBY D+ +PL2X M
DOLBY D+ +PL2Z H
DOLBY D+ +DS
DOLBY D+ +NEO:X C
DOLBY D+ +NEO:X M
DOLBY D+ +NEO:X G
DOLBY HD
DOLBY HD+EX
DOLBY HD+PL2X C
DOLBY HD+PL2X M
DOLBY HD+PL2Z H
DOLBY HD+DS
DOLBY HD+NEO:X C
DOLBY HD+NEO:X M
DOLBY HD+NEO:X G
DTS HD
DTS HD MSTR
DTS HD+PL2X C
DTS HD+PL2X M
DTS HD+PL2Z H
DTS HD+NEO:6
DTS HD+DS
DTS HD+NEO:X C
DTS HD+NEO:X M
DTS HD+NEO:X G
DTS EXPRESS
DTS ES 8CH DSCRT
MPEG2 AAC
AAC+DOLBY EX
AAC+PL2X C
AAC+PL2X M
AAC+PL2Z H
AAC+DS
AAC+NEO:X C
AAC+NEO:X M
AAC+NEO:X G
PL DSX
PL2 C DSX
PL2 M DSX
PL2 G DSX
PL2X C DSX
PL2X M DSX
PL2X G DSX
AUDYSSEY DSX
starkillerOG commented 6 years ago

Yes I have the same section to:


<SurroundMode><Control>1</Control>
<DispName>Sound Mode</DispName>
<GroupList>
<Group>
<GroupName>DIRECT/STEREO</GroupName>
</Group>
<Group>
<GroupName>PURE DIRECT</GroupName>
</Group>
<Group>
<GroupName>Standard</GroupName>
</Group>
<Group>
<GroupName>AUTO</GroupName>
</Group>
<Group>
<GroupName>DSP Simulation</GroupName>
</Group>
</GroupList>
<List>
<Mode>
<IconId>212</IconId>
<GroupName>DIRECT/STEREO</GroupName>
<Name>DIRECT</Name>
</Mode>
<Mode>
<IconId>212</IconId>
<GroupName>DIRECT/STEREO</GroupName>
<Name>STEREO</Name>
</Mode>
<Mode>
<IconId>213</IconId>
<GroupName>PURE DIRECT</GroupName>
<Name>PURE DIRECT</Name>
</Mode>
<Mode>
<IconId>214</IconId>
<GroupName>Standard</GroupName>
<Name>DOLBY DIGITAL</Name>
</Mode>
<Mode>
<IconId>214</IconId>
<GroupName>Standard</GroupName>
<Name>DTS SURROUND</Name>
</Mode>
<Mode>
<IconId>224</IconId>
<GroupName>AUTO</GroupName>
<Name>AUTO</Name>
</Mode>
<Mode>
<IconId>215</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>MULTI CH STEREO</Name>
</Mode>
<Mode>
<IconId>226</IconId>
<GroupName>DSP Simulation</GroupName>
<Name>VIRTUAL</Name>
</Mode>
</List>
<Functions>
<ChangeSurroundMode>1</ChangeSurroundMode>
</Functions>
<ShortcutControl>1</ShortcutControl>
</SurroundMode>

But these also have diffrent spelling than the commads that I need.

Yes I already figured that mapping is the most difficult.

cajuncoding commented 6 years ago

Would this be helpful? I'm not clear what exactly you are looking for, but this version of the Denon IP Control reference has a large master list of commands valid for the higher end receivers . . . and should include the Sound selection commands you referenced above...

https://www.denon.de/de/product/homecinema/avreceiver/avrx1200w?docname=Steuerungsprotokoll_IP_RS232C_AVR-X1200W_AVR-X2200W_AVR-X3200W_AVR-X4200W.pdf

I found it while researching compatible commands for my AVR-X4300H.

starkillerOG commented 6 years ago

@raerae1616 thanks, I also found a simmular document. The commands listed their work for me just the same, but the problem is matching the sound mode status provided by the receiver to one of the (known) commands that can be sent to switch the sound mode (unfortunately they used diffrent spelling for the status the AVR returns and the value to set it).

I did manage to set things on my AVR using: "http://" + DEVICE_IP + "/goform/formiPhoneAppDirect.xml?" + COMMAND_AS_LISTED where the commands are the same as those you provided in the file. However getting the status using something like this failed: "http://" + DEVICE_IP + "/goform/formiPhoneAppDirect.xml?MS?"

starkillerOG commented 6 years ago

Just created a PR, I have implemented the sound mode support in the denonavr library.

starkillerOG commented 6 years ago

@scarface-4711 could you merge my pull request?

ol-iver commented 6 years ago

included into version 0.7.0.