added light state on|off, don't display unreachable lights

This commit is contained in:
mischa 2019-11-03 22:34:36 +01:00
parent 4f8e20befd
commit 875f2ac4ee
1 changed files with 8 additions and 3 deletions

View File

@ -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']}")