klattimer / LGWebOSRemote

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

Interactive mode fails to start #100

Closed harveyrandall closed 11 months ago

harveyrandall commented 2 years ago
Traceback (most recent call last):
  File "/usr/local/bin/lgtv", line 33, in <module>
    sys.exit(load_entry_point('LGTV==0.3', 'console_scripts', 'lgtv')())
  File "/usr/local/lgtv/lib/python3.9/site-packages/LGTV/__init__.py", line 164, in main
    ws = LGTVRemote(name, **config[name])
UnboundLocalError: local variable 'name' referenced before assignment

Given the way the options parsing is structured currently the name of the TV to connect to isn't defined when it attempts to open it. A temporary fix may be to default to the first TV defined in config.json.

A more robust solution would then be to have a general config file (.json or .ini) with defaults, first TV you auth with becomes the default name which the user can change with a separate CLI option config to allow users to get and set their preferences.

[Out of scope: Refactoring __init__.py to use argparser rather than sys.argv & use configparser for user preferences in a .json or .ini file. Happy to do this myself and submit separate PRs for each.]

rjanssen2 commented 2 years ago

Is it clear to you how this works? I get that error on every use of the program, but I have manually put a TV in the config.json file. Is that not enough? It looks like the program reads the file on startup. It looks similar to the example (but with correct info). Is there more that has to be prepared before the program can be used?

klattimer commented 2 years ago

The command arg parsing needs some work, it started out only supporting one TV and was updated to support multiple. Happy to receive PRs

rjanssen2 commented 2 years ago

I'm looking for documentation what is expected in the config file. I am trying to use the software on a server that has 4 network interfaces, the LG TVs being on one of them. It looks like "scan" is not able to handle that, no way to specify an interface. Then, on that network I have 4 LG TVs. I have enabled network control on one of them, and noted down the generated key (displayed by the TV), and put IP, client-key (that value) and its mac-address in a config.json file similar to the example. I verified using strace that it indeed opens that file. But still it doesn't work. So I need to know if this way is going to lead to success or if I completely misunderstand things.

Tenzer commented 11 months ago

I think this ticket probably has been fixed already, via the better argument parsing in https://github.com/klattimer/LGWebOSRemote/pull/128 and allowing a default TV to be specified via https://github.com/klattimer/LGWebOSRemote/pull/137.