Skip to content
Snippets Groups Projects
Unverified Commit 1a8cdba9 authored by On Freund's avatar On Freund Committed by GitHub
Browse files

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
parent 8bacfcec
Branches
Tags
No related merge requests found
...@@ -118,15 +118,20 @@ ONKYO_SELECT_OUTPUT_SCHEMA = vol.Schema( ...@@ -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): ...@@ -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): ...@@ -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")
audio_information_raw = self.command("audio-information query") if self._audio_info_supported:
video_information_raw = self.command("video-information query") audio_information_raw = self.command("audio-information query")
if self._video_info_supported:
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): ...@@ -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): ...@@ -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),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment