commit 51565e99fca280d6809ffa9d8b9cf8573f859b45 from: mischa date: Fri Dec 27 14:46:43 2019 UTC added option to query specific 'id' commit - ef999189ea47ed3aacb0678874837040135f1daa commit + 51565e99fca280d6809ffa9d8b9cf8573f859b45 blob - 9f4c6206d2dbc2a313ec3e68100434265bd52458 blob + f60d94350e737616dc8d361d763e0c59142b0570 --- get-lights.py +++ get-lights.py @@ -23,11 +23,13 @@ import json parser = argparse.ArgumentParser(description="Get all light ids from Hue Bridge") parser.add_argument("bridge", type=str, help="Hue Bridge IP") parser.add_argument("token", type=str, help="Hue API Token") +parser.add_argument("-i", "--id", type=int, help="light id#") try: args = parser.parse_args() bridge = args.bridge token = args.token + id = args.id except argparse.ArgumentError as e: print(str(e)) @@ -42,11 +44,17 @@ with urllib.request.urlopen(req, context=no_cert_check content = response.read() json_data = json.loads(content) - -print(f"{'ID':>3s} {'Name':<32s} {'State':<5s} Type") -print ("################################################################################") -for key in json_data: - if not json_data[key]['state']['reachable']: - continue - state = 'on' if json_data[key]['state']['on'] else 'off' - print(f"{key:>3s}: {json_data[key]['name']:<32s} {state:<5s} {json_data[key]['type']}") +if not id: + print(f"{'ID':>3s} {'Name':<32s} {'State':<5s} Type") + print ("################################################################################") + for key in json_data: + if not json_data[key]['state']['reachable']: + continue + state = 'on' if json_data[key]['state']['on'] else 'off' + print(f"{key:>3s}: {json_data[key]['name']:<32s} {state:<5s} {json_data[key]['type']}") +else: + if json_data[str(id)]['state']['reachable']: + state = 'on' if json_data[str(id)]['state']['on'] else 'off' + print(state) + else: + print("unreachable")