nugget / python-anthemav

Python asyncio module to interface with Anthem AVM and MRX receivers
MIT License
15 stars 26 forks source link

Support STR pre-amplifier and integrated amplifier #40

Open iain-cx opened 1 year ago

iain-cx commented 1 year ago

Addresses #38.

The STR pre-amplifier supports four listening modes: Stereo, Mono, Both left and Both right.

It only has one zone.

Minimum and maximum volume is -96.0dB and +7.0dB. Volume can be set in 0.5dB increments. This PR reworks volume_to_attenuation() and attenuation_to_volume() to handle this case, while preserving the -90dB to 0dB range of other devices. Note that in doing so we change the type of volume from int to float. Regression testing is advised.

The device supports Home Theatre Bypass mode AKA HTB, in which the output from a separate AV receiver can be connected to the pre-amplifier, which will pass through the signal to the connected power amplifier when the pre-amplifier is in standby mode. HTB inputs are discussed in #38, however they are not able to be selected independently. The official Anthem app does show them in the input list, but fails to switch to them. They don't show up at all on the device front panel. It is therefore probably not a bug that this library cannot select them.

Several commands which apply to AV receivers are not supported by the STR. In particular, BRT is the read-only bitrate property on a receiver, but the read/write left/right channel balance adjust on the pre-amplifier. The Z1BRT0 commands adjusts balance to the right channel by 0.5dB, Z1BRT50 adjusts by 2.5dB and Z1BRT100 adjusts by 5dB (the maximum), At startup most devices would receive Z1BRT? to query the current source bitrate, but the STR (probably incorrectly) interprets the command as Z1BRT0. After instantiating the AVR class ten times, you would see your pre-amplifier shift the balance fully to the right. We now avoid doing that by adding BRT to the list of commands which should not be sent at connection startup, as well as other commands which are not mentioned in the documentation from Anthem.

mattlathrop commented 1 year ago

HTB is Input 32. A name isn't returned but you can tell it to switch to 32 and it does work. I'm working on a fork of your code to add this.

mattlathrop commented 1 year ago

I've opened a PR on this PR (maybe there was a better way to do that..) but you can find it here. https://github.com/iain-cx/python-anthemav/pull/1

iain-cx commented 1 year ago

HTB is Input 32. A name isn't returned but you can tell it to switch to 32 and it does work.

Executive summary: input 32 doesn't work for me.

I actually came to the conclusion that Anthem doesn't want us to go into the menu and set up an input for HTB. When you configure bypass in the settings, you choose either an RCA or XLR jack to use for it, and HTB will then work regardless of whether or not you configure an input.

In fact you can't actually configure an input using a jack that you already configured for HTB, and if you do configure one first, then subsequently configure the jack, the input shows up with the HTB suffix in the input list but you can't select it either on the front panel or with the Anthem app.

All of this leads me to conclude that you aren't supposed to set up an input at all, although the documentation doesn't make that clear, given that you and I, amongst others, read it and thought that we were supposed to.

Right now I don't have an input configured for HTB, and when I tried to select input 32 nothing happens.

If I telnet to port 14999 and send Z1INP32 I just get an error response from the device. When I did have an input configured, sending the raw input switching command with the number of my input also failed.

I'm on firmware 1.8.30. Maybe it's different on older versions but I'm not sure that special casing input 32 is the right thing to do.

iain-cx commented 1 year ago

I've opened a PR on this PR (maybe there was a better way to do that..) but you can find it here. iain-cx#1

Heh, I don't know what the best way to handle a PR on PR situation is, either. But I would propose that we discuss the changes here, for clarity.

Regardless of what I wrote above about HTB, the float handling stuff looks good and I can certainly merge it and repush here.

mattlathrop commented 1 year ago

HTB is Input 32. A name isn't returned but you can tell it to switch to 32 and it does work.

Executive summary: input 32 doesn't work for me.

I actually came to the conclusion that Anthem doesn't want us to go into the menu and set up an input for HTB. When you configure bypass in the settings, you choose either an RCA or XLR jack to use for it, and HTB will then work regardless of whether or not you configure an input.

In fact you can't actually configure an input using a jack that you already configured for HTB, and if you do configure one first, then subsequently configure the jack, the input shows up with the HTB suffix in the input list but you can't select it either on the front panel or with the Anthem app.

All of this leads me to conclude that you aren't supposed to set up an input at all, although the documentation doesn't make that clear, given that you and I, amongst others, read it and thought that we were supposed to.

Right now I don't have an input configured for HTB, and when I tried to select input 32 nothing happens.

If I telnet to port 14999 and send Z1INP32 I just get an error response from the device. When I did have an input configured, sending the raw input switching command with the number of my input also failed.

I'm on firmware 1.8.30. Maybe it's different on older versions but I'm not sure that special casing input 32 is the right thing to do.

I reached out the Anthem support ages ago about this and they said it was definitely possible to switch to HTB. My guess is it depends on which I put you select? Can you try RCA4 and see if that makes it 32? If not could you start up the monitor in this code and switch to HTB to see which input it reports?

iain-cx commented 1 year ago

Can you try RCA4 and see if that makes it 32?

I set it for subwoofer bypass, since only RCA3 can be set for fronts, but even then there was no difference. The input appeared in the list with HTB suffix and I couldn't select it with the front panel, the Anthem app or this library.

If not could you start up the monitor in this code and switch to HTB to see which input it reports?

It reports the input it was on before I tried to switch, because I can't switch.

mattlathrop commented 1 year ago

Huh so how do you get into HTB? Which equipment are you using? I can certainly switch to the input on the front panel.

iain-cx commented 1 year ago

The front left/right channels from my AV receiver is connected to RCA3, which is configured for HTB Fronts. I only have one subwoofer, so its output from the receiver is connected to RCA4 left, and RCA4 is configured for HTB Sub.

To enter bypass, I switch the pre-amplifier to standby mode, which flips the relays to connect RCA3 and RCA4 directly to the device outputs, ie my power amplifier and subwoofer.

That's the way the documentation says to do it, as I recall.

mattlathrop commented 1 year ago

Do you have the separates or the integrated? I think that may be the difference? For me (integrated) I can only pick a single input as HTB. To switch to it I have to power on the integrated (obviously since if it was off the power amp would be off) and switch to the input labeled HTB RCAX (or XLR). It does seem to be 32 regardless of which input I pick to be HTB. It sounds like we may need to special case the integrated and the pre-amp since they handle this differently?

iain-cx commented 1 year ago

Aha that's the difference. Yes, I have the separates. The pre-amplifier identifies itself with IDMSTR PA. According to Anthem's documentation, the integrated should respond with IDMSTR IA, in which case we can detect it separately.

mattlathrop commented 1 year ago

Yep! IDMSTR IA is correct. Just verified.

mattlathrop commented 1 year ago

@iain-cx I updated my PR real quick. Could you test when you get some time on your PA?

iain-cx commented 1 year ago

Looks good.

Hyralex commented 1 year ago

Sorry for the delay. I'm concerned that this won't work with HA properly. It looks like you ignore the MAC command, but this commands (or any other command to get the mac address) is required for the HA integration. This is how we define the unique device ID. While it could work in theory with 1 unit, you would run into issues if you have a second unit. Is there any command that can return the MAC address of the device?

iain-cx commented 1 year ago

The supported way to get the MAC address on these devices (as well as on x20 receivers and other devices) is to send IDN?.