From 875f2ac4ee37b30febab85ab44f41606ec344c2e Mon Sep 17 00:00:00 2001 From: mischa Date: Sun, 3 Nov 2019 22:34:36 +0100 Subject: [PATCH] added light state on|off, don't display unreachable lights --- get-lights.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/get-lights.py b/get-lights.py index 522d2b0..0543d79 100755 --- a/get-lights.py +++ b/get-lights.py @@ -2,8 +2,9 @@ # # Copyright 2019, Mischa Peters , 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 @@ -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']}")