commit ef999189ea47ed3aacb0678874837040135f1daa from: mischa date: Fri Dec 27 14:45:35 2019 UTC added 'state' function commit - b455762fa20af256019440e420831946f8fab374 commit + ef999189ea47ed3aacb0678874837040135f1daa blob - 64a9281018e28cd83b7799c1e24a2a0863062a05 blob + 52cf1637cd35df690424ceb606881dd3e88e985e --- lightctl.py +++ lightctl.py @@ -23,7 +23,7 @@ parser = argparse.ArgumentParser(description="Control parser.add_argument("bridge", type=str, help="Hue Bridge IP") parser.add_argument("token", type=str, help="Hue API Token") parser.add_argument("-l", "--light", type=int, required=True, help="light id#") -parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight") +parser.add_argument("-a", "--action", type=str, default='on', help="on|off|relax|bright|dimmed|nightlight|state") parser.add_argument("-v", "--verbose", action='store_true', help="verbose") parser.add_argument("-d", "--debug", action='store_true', help="debug") @@ -71,7 +71,11 @@ def get_state(id): json_data = json.loads(content) if debug: print (f"State for light id {id}:\n{json_data['state']}") if debug: print (f"Type for light id {id}: {json_data['config']['archetype']}") - return (json_data['state']) + if 'state' in json_data: + return (json_data['state']) + else: + print(f"id {id} doesn't exist") + return -1 def put_state(id, state): if not 'colormode' in state: @@ -100,4 +104,11 @@ def put_state(id, state): return(res) light_state = get_state(light) -put_state(light, light_state) +if not action == 'state': + put_state(light, light_state) +else: + if light_state['reachable']: + state = 'on' if light_state['on'] else 'off' + print(state) + else: + print("unreachable")