TV prompts permission before allowing connecting in all sessions
PMtthews opened this issue · 4 comments
Hi supersaiyanmode.
Awesome library. Love it, use it daily (esp as the family often loses the actual remote multiple times within an evening...). Thanks so much for putting this out there.
A slight issue I'm having (more of a convenience thing, really) is that, every time I connect, the TV prompts a Y/N permission request (titled "Connection Request: LG Remote App") that must be manually approved/declined before python can connect.
This often isn't an issue if we have the physical remote on hand, but if the remote is lost (as is often the case) I'm unable to accept the connection request and so we start tearing apart the sofa looking for the actual remote.
Is there any way to 'store' the approval so that the TV automatically approves the connection?
Totally fine if not - I'll still be using and loving your library regardless of whether this is possible, I just thought I'd better ask :)
Thanks again for building this!
Hi PMtthews, Thanks so much 👍
The store
that gets passed is a dictionary-like object. The client.register(..)
reads an existing token from the object against the key "client_key"
(See: https://github.com/supersaiyanmode/PyWebOSTV/blob/master/pywebostv/connection.py#L125).
I'd suggest creating a new dict-like class (implement __getitem__(..)
and __setitem__(..)
) such that they will read/write from/to file or a database. You can then pass the instance to the the register(..)
method. Things should just work. :)
Look in the example provided in the readme, it's the store
variable indeed:
https://github.com/supersaiyanmode/PyWebOSTV#establishing-the-connection
Closing this issue. Feel free to re-open if you have questions
Just wanted to add in order for me to get this to work I also had to implement __contains__. I think it is needed to satisfy "if "client_key" in store:".
Here is my complete implementation:
class Storage(dict):
def __setitem__(self, index, value):
self.__dict__[index] = value
with open("registration.txt","w") as f:
json.dump(self.__dict__,f)
def __getitem__(self, index):
with open("registration.txt") as f:
self.__dict__ = json.load(f)
return self.__dict__[index]
def __contains__(self, item):
with open("registration.txt") as f:
self.__dict__ = json.load(f)
return item in self.__dict__