CLI: allow websocket connection by specifying api token.
This commit is contained in:
parent
d881f73fde
commit
5ebf6c8aa1
|
@ -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 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_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 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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,9 @@ class NeoHubCLIArgumentError(Error):
|
||||||
class NeoHubCLI(object):
|
class NeoHubCLI(object):
|
||||||
"""A runner for neohub_cli operations."""
|
"""A runner for neohub_cli operations."""
|
||||||
|
|
||||||
def __init__(self, command, args, hub_ip=None, hub_port=4242):
|
def __init__(self, command, args, hub_ip=None, hub_token=None):
|
||||||
self._hub = NeoHub(host=hub_ip, port=hub_port)
|
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._command = command
|
||||||
self._args = args
|
self._args = args
|
||||||
# live data cached from the neohub. We assume this data will remain current
|
# live data cached from the neohub. We assume this data will remain current
|
||||||
|
@ -279,8 +280,7 @@ class NeoHubCLI(object):
|
||||||
async def main():
|
async def main():
|
||||||
argp = argparse.ArgumentParser(description='CLI to neohub devices')
|
argp = argparse.ArgumentParser(description='CLI to neohub devices')
|
||||||
argp.add_argument('--hub_ip', help='IP address of NeoHub', default=None)
|
argp.add_argument('--hub_ip', help='IP address of NeoHub', default=None)
|
||||||
argp.add_argument(
|
argp.add_argument('--hub_token', help='API token', default=None)
|
||||||
'--hub_port', help='Port number of NeoHub to talk to', default=4242)
|
|
||||||
argp.add_argument('--format', help='Output format', default='list')
|
argp.add_argument('--format', help='Output format', default='list')
|
||||||
argp.add_argument('command', help='Command to issue')
|
argp.add_argument('command', help='Command to issue')
|
||||||
argp.add_argument('arg', help='Arguments to command', nargs='*')
|
argp.add_argument('arg', help='Arguments to command', nargs='*')
|
||||||
|
@ -291,7 +291,8 @@ async def main():
|
||||||
args.command,
|
args.command,
|
||||||
args.arg,
|
args.arg,
|
||||||
hub_ip=args.hub_ip,
|
hub_ip=args.hub_ip,
|
||||||
hub_port=args.hub_port)
|
hub_token=args.hub_token,
|
||||||
|
)
|
||||||
m = await nhc.callable()
|
m = await nhc.callable()
|
||||||
if m:
|
if m:
|
||||||
result = await m()
|
result = await m()
|
||||||
|
|
Loading…
Reference in New Issue