Gracefully handle missing A/V info in Onkyo integration (#46228)

* Gracefully handle missing A/V info

* Do not attempt to query A/V info if unsupported

* Rename _parse_onkyo_tuple
This commit is contained in:
On Freund 2021-02-13 13:03:49 +02:00 committed by GitHub
parent 8bacfcec50
commit 1a8cdba9af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -118,15 +118,20 @@ ONKYO_SELECT_OUTPUT_SCHEMA = vol.Schema(
SERVICE_SELECT_HDMI_OUTPUT = "onkyo_select_hdmi_output" SERVICE_SELECT_HDMI_OUTPUT = "onkyo_select_hdmi_output"
def _parse_onkyo_tuple(tup): def _parse_onkyo_payload(payload):
"""Parse a tuple returned from the eiscp library.""" """Parse a payload returned from the eiscp library."""
if len(tup) < 2: if isinstance(payload, bool):
# command not supported by the device
return False
if len(payload) < 2:
# no value
return None return None
if isinstance(tup[1], str): if isinstance(payload[1], str):
return tup[1].split(",") return payload[1].split(",")
return tup[1] return payload[1]
def _tuple_get(tup, index, default=None): def _tuple_get(tup, index, default=None):
@ -267,6 +272,8 @@ class OnkyoDevice(MediaPlayerEntity):
self._reverse_mapping = {value: key for key, value in sources.items()} self._reverse_mapping = {value: key for key, value in sources.items()}
self._attributes = {} self._attributes = {}
self._hdmi_out_supported = True self._hdmi_out_supported = True
self._audio_info_supported = True
self._video_info_supported = True
def command(self, command): def command(self, command):
"""Run an eiscp command and catch connection errors.""" """Run an eiscp command and catch connection errors."""
@ -309,12 +316,14 @@ class OnkyoDevice(MediaPlayerEntity):
else: else:
hdmi_out_raw = [] hdmi_out_raw = []
preset_raw = self.command("preset query") preset_raw = self.command("preset query")
if self._audio_info_supported:
audio_information_raw = self.command("audio-information query") audio_information_raw = self.command("audio-information query")
if self._video_info_supported:
video_information_raw = self.command("video-information query") video_information_raw = self.command("video-information query")
if not (volume_raw and mute_raw and current_source_raw): if not (volume_raw and mute_raw and current_source_raw):
return return
sources = _parse_onkyo_tuple(current_source_raw) sources = _parse_onkyo_payload(current_source_raw)
for source in sources: for source in sources:
if source in self._source_mapping: if source in self._source_mapping:
@ -441,7 +450,11 @@ class OnkyoDevice(MediaPlayerEntity):
self.command(f"hdmi-output-selector={output}") self.command(f"hdmi-output-selector={output}")
def _parse_audio_information(self, audio_information_raw): def _parse_audio_information(self, audio_information_raw):
values = _parse_onkyo_tuple(audio_information_raw) values = _parse_onkyo_payload(audio_information_raw)
if values is False:
self._audio_info_supported = False
return
if values: if values:
info = { info = {
"format": _tuple_get(values, 1), "format": _tuple_get(values, 1),
@ -456,7 +469,11 @@ class OnkyoDevice(MediaPlayerEntity):
self._attributes.pop(ATTR_AUDIO_INFORMATION, None) self._attributes.pop(ATTR_AUDIO_INFORMATION, None)
def _parse_video_information(self, video_information_raw): def _parse_video_information(self, video_information_raw):
values = _parse_onkyo_tuple(video_information_raw) values = _parse_onkyo_payload(video_information_raw)
if values is False:
self._video_info_supported = False
return
if values: if values:
info = { info = {
"input_resolution": _tuple_get(values, 1), "input_resolution": _tuple_get(values, 1),