11import asyncio
2+
3+ import requests
4+ from defusedxml import DefusedXmlException
5+ from defusedxml .ElementTree import fromstring
26from denonavr import DenonAVR
37from .base import AudioAmplifier
48
59class DenonAVRController (AudioAmplifier ):
610
7- def __init__ (self , host : str ):
11+ def __init__ (self , host : str , port : int = 10443 ):
812 self .receiver = DenonAVR (host )
13+ self .url = f"https://{ host } :{ port } /"
914 self .setup ()
1015
1116 def setup (self ):
@@ -76,3 +81,28 @@ def get_status(self):
7681 "input" : self .get_input (),
7782 "sound_mode" : self .get_sound_mode (),
7883 }
84+
85+ def get_audio_format (self ):
86+ """
87+ Web interface was showing input audio format. Could not find an equivalent method from
88+ denonavr package. We need to get the inputSignal details, Searched whole package to find
89+ any reference of inputSignal, but could not find. So using the web api itself here.
90+
91+ Returns:
92+ str: 'Dolby Atmos', 'PCM'
93+ Raises:
94+ ValueError: if could not find or parse the data
95+ """
96+ try :
97+ # The 'type=12' query parameter requests the configuration from the Denon AVR.
98+ # the certificates in denon avr showed expired even after firmware update. so added verify=False
99+ response = requests .get (f'{ self .url } ajax/general/get_config?type=12' , verify = False , timeout = 15 )
100+ if response .status_code == 200 :
101+ xml_data = fromstring (response .content )
102+ element = xml_data .find (".//InputSignal" )
103+ return element .text if element is not None else None
104+ raise ValueError (f"Failed to fetch Audio format. Status code: { response .status_code } " )
105+ except DefusedXmlException :
106+ raise ValueError ("Failed to parse AVR response." )
107+ except requests .exceptions .RequestException :
108+ raise ValueError ("Can't reach AVR. Please check configuration" )
0 commit comments