Skip to content

Commit

Permalink
Merge pull request #11 from gerard33/cleanup
Browse files Browse the repository at this point in the history
Cleanup and PR8 implemented
  • Loading branch information
gerard33 authored Jul 22, 2019
2 parents 31ad0a8 + a33b4f2 commit 2ffabb4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions braviapsk/sony_bravia_psk.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def connect(self, pin, clientid, nickname):
except requests.exceptions.HTTPError as exception_instance:
_LOGGER.error("[W] HTTPError: " + str(exception_instance))
return False

except requests.exceptions.Timeout as exception_instance:
_LOGGER.error("[W] Timeout occurred: " + str(exception_instance))
return False
Expand Down Expand Up @@ -126,6 +126,8 @@ def _wakeonlan(self):

def send_req_ircc(self, params, log_errors=True):
"""Send an IRCC command via HTTP to Sony Bravia."""
if params is None:
return False
headers = {'X-Auth-PSK': self._psk, 'SOAPACTION': '"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"'}
data = ("<?xml version=\"1.0\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org" +
"/soap/envelope/\" " +
Expand All @@ -141,7 +143,7 @@ def send_req_ircc(self, params, log_errors=True):
except requests.exceptions.HTTPError as exception_instance:
if log_errors:
_LOGGER.error("HTTPError: " + str(exception_instance))

except requests.exceptions.Timeout as exception_instance:
if log_errors:
_LOGGER.error("Timeout occurred: " + str(exception_instance))
Expand Down Expand Up @@ -264,7 +266,9 @@ def _refresh_commands(self):
if not resp.get('error'):
self._commands = resp.get('result')[1]
else:
_LOGGER.error("JSON request error: " + json.dumps(resp, indent=4))
error = resp.get('error')
if "not power-on" not in error:
_LOGGER.error("JSON request error: " + json.dumps(resp, indent=4))

def get_command_code(self, command_name):
if len(self._commands) == 0:
Expand Down Expand Up @@ -376,7 +380,7 @@ def media_previous_track(self):
self.send_req_ircc(self.get_command_code('Prev'))

def add_seconds(self, tm, secs):
"""Adds seconds to time (HH:MM:SS)."""
"""Adds seconds to time (HH:MM:SS)."""
fulldate = datetime.datetime(100, 1, 1, tm.hour, tm.minute, tm.second)
fulldate = fulldate + datetime.timedelta(seconds=secs)
return fulldate.time()
Expand Down

0 comments on commit 2ffabb4

Please sign in to comment.