added light state on|off, don't display unreachable lights
This commit is contained in:
parent
4f8e20befd
commit
875f2ac4ee
|
@ -2,8 +2,9 @@
|
|||
#
|
||||
# Copyright 2019, Mischa Peters <mischa AT high5 DOT nl>, High5!.
|
||||
# Version 1.0 - 20191028
|
||||
# Version 1.1 - 20191103 - added ['state']['on']
|
||||
#
|
||||
# Get all light IDs
|
||||
# Get all light ids and state
|
||||
#
|
||||
# For example:
|
||||
# $ get-lights.py <bridge IP> <token>
|
||||
|
@ -41,7 +42,11 @@ with urllib.request.urlopen(req, context=no_cert_check) as response:
|
|||
content = response.read()
|
||||
json_data = json.loads(content)
|
||||
|
||||
print(f"{'ID':>2s}: {'Name':<30s} Type")
|
||||
|
||||
print(f"{'ID':>2s}: {'Name':<32} {'State':<5s} Type")
|
||||
print ("################################################################################")
|
||||
for key in json_data:
|
||||
print(f"{key:>2s}: {json_data[key]['name']:<32s} {json_data[key]['type']}")
|
||||
if not json_data[key]['state']['reachable']:
|
||||
continue
|
||||
state = 'on' if json_data[key]['state']['on'] else 'off'
|
||||
print(f"{key:>2s}: {json_data[key]['name']:<32s} {state:<5s} {json_data[key]['type']}")
|
||||
|
|
Loading…
Reference in New Issue