commit 875f2ac4ee37b30febab85ab44f41606ec344c2e from: mischa date: Sun Nov 3 21:34:36 2019 UTC added light state on|off, don't display unreachable lights commit - 4f8e20befd48d6a97f8b16757d71f927e5891e1f commit + 875f2ac4ee37b30febab85ab44f41606ec344c2e blob - 522d2b032d1ca49c5d94ec3b59cfb5c6c4dac84a blob + 0543d79e72f77721425d46cd73886b4c27e0b8db --- get-lights.py +++ 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 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']}")