From 0d86372e0897a55ac790eaa25a777f0f6a3d4d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Fri, 20 Aug 2021 23:29:27 +0200 Subject: [PATCH] Add load_app_list API and some minor extras (#18) Adapted @89jd's PR from https://github.com/aparraga/braviarc/pull/34 to the code of this fork. --- braviapsk/sony_bravia_psk.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/braviapsk/sony_bravia_psk.py b/braviapsk/sony_bravia_psk.py index a11151c..e2134a7 100644 --- a/braviapsk/sony_bravia_psk.py +++ b/braviapsk/sony_bravia_psk.py @@ -37,7 +37,7 @@ def __init__( self._commands = [] self._content_mapping = [] - def _jdata_build(self, method, params): + def _jdata_build(self, method, params=None): if params: ret = json.dumps( {"method": method, "params": [params], "id": 1, "version": "1.0"} @@ -97,15 +97,15 @@ def connect(self, pin, clientid, nickname): response.raise_for_status() except requests.exceptions.HTTPError as exception_instance: - _LOGGER.error("[W] HTTPError: " + str(exception_instance)) + _LOGGER.exception("[W] HTTPError: " + str(exception_instance)) return False except requests.exceptions.Timeout as exception_instance: - _LOGGER.error("[W] Timeout occurred: " + str(exception_instance)) + _LOGGER.exception("[W] Timeout occurred: " + str(exception_instance)) return False except Exception as exception_instance: # pylint: disable=broad-except - _LOGGER.error("[W] Exception: " + str(exception_instance)) + _LOGGER.exception("[W] Exception: " + str(exception_instance)) return False else: @@ -215,6 +215,16 @@ def send_command(self, command): """Send command to the TV.""" self.send_req_ircc(self.get_command_code(command)) + def load_app_list(self): + """Get the list of installed apps.""" + resp = self.bravia_req_json( + "sony/appControl", self._jdata_build("getApplicationList") + ) + if resp.get("error"): + _LOGGER.error("ERROR: %s" % resp.get("error")) + else: + return resp.get("result")[0] + def open_app(self, uri): """Open app with given uri.""" resp = self.bravia_req_json( @@ -279,6 +289,7 @@ def load_source_list(self): "extInput:hdmi", "extInput:composite", "extInput:component", + "extInput:cec", ): # physical inputs resp = self.bravia_req_json( "sony/avContent", self._jdata_build("getContentList", result) @@ -370,6 +381,8 @@ def get_system_info(self): system_content_data = resp.get("result")[0] return_value["name"] = system_content_data.get("name") return_value["model"] = system_content_data.get("model") + return_value["mac"] = system_content_data.get("mac") + return_value["serial"] = system_content_data.get("serial") return_value["language"] = system_content_data.get("language") return return_value