CLI: allow websocket connection by specifying api token.

This commit is contained in:
Vlad Firoiu 2023-10-24 18:44:52 +01:00
parent d881f73fde
commit 5ebf6c8aa1
2 changed files with 7 additions and 6 deletions

View File

@ -54,5 +54,5 @@ $ neohub_cli.py help # Shows all commands
$ neohub_cli.py help set_time # Displays help for the set_time function
$ neohub_cli.py --hub_ip=myneohub set_time "2021-01-31 15:43:00" # Specify times like this
$ neohub_cli.py --hub_ip=myneohub set_lock 1234 "Living Room" # Name NeoStats like this.
$ neohub_cli.py --hub_ip=myneohub --hub_token=XXX get_system # Get system variables with websocket connection
```

View File

@ -35,8 +35,9 @@ class NeoHubCLIArgumentError(Error):
class NeoHubCLI(object):
"""A runner for neohub_cli operations."""
def __init__(self, command, args, hub_ip=None, hub_port=4242):
self._hub = NeoHub(host=hub_ip, port=hub_port)
def __init__(self, command, args, hub_ip=None, hub_token=None):
hub_port = 4242 if hub_token is None else 4243
self._hub = NeoHub(host=hub_ip, port=hub_port, token=hub_token)
self._command = command
self._args = args
# live data cached from the neohub. We assume this data will remain current
@ -279,8 +280,7 @@ class NeoHubCLI(object):
async def main():
argp = argparse.ArgumentParser(description='CLI to neohub devices')
argp.add_argument('--hub_ip', help='IP address of NeoHub', default=None)
argp.add_argument(
'--hub_port', help='Port number of NeoHub to talk to', default=4242)
argp.add_argument('--hub_token', help='API token', default=None)
argp.add_argument('--format', help='Output format', default='list')
argp.add_argument('command', help='Command to issue')
argp.add_argument('arg', help='Arguments to command', nargs='*')
@ -291,7 +291,8 @@ async def main():
args.command,
args.arg,
hub_ip=args.hub_ip,
hub_port=args.hub_port)
hub_token=args.hub_token,
)
m = await nhc.callable()
if m:
result = await m()