klattimer / LGWebOSRemote

Command line webOS remote for LGTVs
MIT License
518 stars 99 forks source link

Problem when calling lgtv.sh from child process in node.js #42

Closed blefjell closed 5 years ago

blefjell commented 5 years ago

Hi and thanks for your great libary! I have succesfully installed it on my pi and I can controll the TV from a command line. I am trying to integrate it into my HAP-Node.js, so I can for example turn on my TV. To do this I call lgtv.sh as a child process with exec('/home/pi/LGWebOSRemote/lgtv.sh on'); Unfortunately I get this error: stdout: stderr: Traceback (most recent call last): File "lgtv.py", line 87, in ws = LGTVClient() File "/home/pi/LGWebOSRemote/LGTV/init.py", line 217, in init super(LGTVClient, self).init('ws://' + self.__hostname + ':3000/', exclude_headers=["Origin"]) TypeError: cannot concatenate 'str' and 'NoneType' objects

exec error: Error: Command failed: /home/pi/LGWebOSRemote/lgtv.sh inputChannelDown Traceback (most recent call last): File "lgtv.py", line 87, in ws = LGTVClient() File "/home/pi/LGWebOSRemote/LGTV/init.py", line 217, in init super(LGTVClient, self).init('ws://' + self.__hostname + ':3000/', exclude_headers=["Origin"]) TypeError: cannot concatenate 'str' and 'NoneType' objects

Can you give any advice on this? Thanks in advance!

klattimer commented 5 years ago

Yeah, it seems that it can't find the config file and load it correctly.

wnf58 commented 5 years ago

In your HAP-Node.js you are not the same user as in command line.

LGTVClient load the config file from home path of the user: class LGTVClient(WebSocketClient): def __init__(self, hostname=None): self.__command_count = 0 self.__waiting_callback = None if os.path.exists(os.path.expanduser("~/.lgtv.json")): f = open(os.path.expanduser("~/.lgtv.json")) settings = json.loads(f.read()) f.close()

blefjell commented 5 years ago

Thanks for the quick replies!! I am sorry, I don't know a lot about both Node.js and python. Do you have a suggestion how I would get around that problem? Where is the lgtv.json file actually saved? I can't seem to find it.

blefjell commented 5 years ago

I made it work. I noticed, that I run HAP-Node.js as sudo, so I reran auth with sudo and now it works :) Thanks for your advice!