Handle session internally
This commit is contained in:
parent
30e6ec309e
commit
be48542115
2 changed files with 7 additions and 8 deletions
|
@ -32,10 +32,9 @@ remote.set_pairing_key(key)
|
||||||
```
|
```
|
||||||
|
|
||||||
After this you can send single or multiple commands using `send_command` and `send_multiple`.
|
After this you can send single or multiple commands using `send_command` and `send_multiple`.
|
||||||
2011 Models initiate a session key. This currently still needs to be passed every time you call `send_command`
|
|
||||||
|
|
||||||
```
|
```
|
||||||
remote.send_command(Remote.VOLUME_UP, remote.session)
|
remote.send_command(Remote.audio_controls["VOLUME_UP"])
|
||||||
|
|
||||||
commands = [Remote.HOME, Remote.EXIT, Remote.MENU]
|
commands = [Remote.HOME, Remote.EXIT, Remote.MENU]
|
||||||
remote.send_multiple(commands)
|
remote.send_multiple(commands)
|
||||||
|
|
10
lg.py
10
lg.py
|
@ -23,13 +23,13 @@ class Remote():
|
||||||
|
|
||||||
self.pair_key = pair_key
|
self.pair_key = pair_key
|
||||||
self.ip_address = ip_address
|
self.ip_address = ip_address
|
||||||
self.session = None
|
self.__session = None
|
||||||
|
|
||||||
if not self.ip_address:
|
if not self.ip_address:
|
||||||
raise Remote.NoTVFound
|
raise Remote.NoTVFound
|
||||||
|
|
||||||
if self.pair_key:
|
if self.pair_key:
|
||||||
self.session = self.get_session()
|
self.__session = self.get_session()
|
||||||
else:
|
else:
|
||||||
self.request_pair()
|
self.request_pair()
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class Remote():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.pair_key = pair_key
|
self.pair_key = pair_key
|
||||||
self.session = self.get_session()
|
self.__session = self.get_session()
|
||||||
|
|
||||||
def make_request(self, endpoint, content, extra_headers={}):
|
def make_request(self, endpoint, content, extra_headers={}):
|
||||||
"""
|
"""
|
||||||
|
@ -126,7 +126,7 @@ class Remote():
|
||||||
response = self.make_request('/hdcp/api/auth', content)
|
response = self.make_request('/hdcp/api/auth', content)
|
||||||
return response.find('session').text
|
return response.find('session').text
|
||||||
|
|
||||||
def send_command(self, code, session):
|
def send_command(self, code):
|
||||||
"""
|
"""
|
||||||
Send a remote control key command. Ignores response for now.
|
Send a remote control key command. Ignores response for now.
|
||||||
"""
|
"""
|
||||||
|
@ -140,7 +140,7 @@ class Remote():
|
||||||
<type>HandleKeyInput</type>
|
<type>HandleKeyInput</type>
|
||||||
<value>{0}</value>
|
<value>{0}</value>
|
||||||
</command>
|
</command>
|
||||||
""".format(code, session)
|
""".format(code, self.__session)
|
||||||
self.make_request('/hdcp/api/dtv_wifirc', content)
|
self.make_request('/hdcp/api/dtv_wifirc', content)
|
||||||
|
|
||||||
def send_multiple(self, codes, delay=0.2):
|
def send_multiple(self, codes, delay=0.2):
|
||||||
|
|
Loading…
Reference in a new issue