Handle session internally

This commit is contained in:
sqozz 2019-01-31 19:31:11 +01:00
parent 30e6ec309e
commit be48542115
2 changed files with 7 additions and 8 deletions

View file

@ -32,10 +32,9 @@ remote.set_pairing_key(key)
```
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]
remote.send_multiple(commands)
@ -43,4 +42,4 @@ remote.send_multiple(commands)
An optional `delay` parameter can be provided to `send_multiple`; this will the amount of seconds the control will wait between commands. N.B. Sending commands too fast can cause some of them to be ignored.
Shortcuts-structure is subject to change. They still can be looked up in `lg.py`. Be careful on your journey!
Shortcuts-structure is subject to change. They still can be looked up in `lg.py`. Be careful on your journey!

10
lg.py
View file

@ -23,13 +23,13 @@ class Remote():
self.pair_key = pair_key
self.ip_address = ip_address
self.session = None
self.__session = None
if not self.ip_address:
raise Remote.NoTVFound
if self.pair_key:
self.session = self.get_session()
self.__session = self.get_session()
else:
self.request_pair()
@ -83,7 +83,7 @@ class Remote():
"""
self.pair_key = pair_key
self.session = self.get_session()
self.__session = self.get_session()
def make_request(self, endpoint, content, extra_headers={}):
"""
@ -126,7 +126,7 @@ class Remote():
response = self.make_request('/hdcp/api/auth', content)
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.
"""
@ -140,7 +140,7 @@ class Remote():
<type>HandleKeyInput</type>
<value>{0}</value>
</command>
""".format(code, session)
""".format(code, self.__session)
self.make_request('/hdcp/api/dtv_wifirc', content)
def send_multiple(self, codes, delay=0.2):