Skip to content

Commit

Permalink
Add load_app_list API and some minor extras (#18)
Browse files Browse the repository at this point in the history
Adapted @89jd's PR from antonioparraga/braviarc#34
to the code of this fork.
  • Loading branch information
rchl authored Aug 20, 2021
1 parent 69ecbdb commit 0d86372
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions braviapsk/sony_bravia_psk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0d86372

Please sign in to comment.