added 'state' function
This commit is contained in:
parent
b455762fa2
commit
ef999189ea
17
lightctl.py
17
lightctl.py
@ -23,7 +23,7 @@ parser = argparse.ArgumentParser(description="Control light")
|
|||||||
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
parser.add_argument("bridge", type=str, help="Hue Bridge IP")
|
||||||
parser.add_argument("token", type=str, help="Hue API Token")
|
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("-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("-v", "--verbose", action='store_true', help="verbose")
|
||||||
parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
parser.add_argument("-d", "--debug", action='store_true', help="debug")
|
||||||
|
|
||||||
@ -71,7 +71,11 @@ def get_state(id):
|
|||||||
json_data = json.loads(content)
|
json_data = json.loads(content)
|
||||||
if debug: print (f"State for light id {id}:\n{json_data['state']}")
|
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']}")
|
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):
|
def put_state(id, state):
|
||||||
if not 'colormode' in state:
|
if not 'colormode' in state:
|
||||||
@ -100,4 +104,11 @@ def put_state(id, state):
|
|||||||
return(res)
|
return(res)
|
||||||
|
|
||||||
light_state = get_state(light)
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user