added -b option for battery test only to use with cron
This commit is contained in:
parent
eb78856c45
commit
1dd8b4e202
|
@ -26,11 +26,15 @@ import collections
|
||||||
parser = argparse.ArgumentParser(description="Get all sensor ids from Hue Bridge")
|
parser = argparse.ArgumentParser(description="Get all sensor ids from Hue Bridge")
|
||||||
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("-b", "--battery", type=int, help="battery check only, threshold, default 20")
|
||||||
|
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
bridge = args.bridge
|
bridge = args.bridge
|
||||||
token = args.token
|
token = args.token
|
||||||
|
battery = args.battery
|
||||||
|
verbose = args.verbose
|
||||||
|
|
||||||
except argparse.ArgumentError as e:
|
except argparse.ArgumentError as e:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
|
@ -58,10 +62,15 @@ for key in json_data:
|
||||||
|
|
||||||
for key in sensors:
|
for key in sensors:
|
||||||
for i in sensors[key]:
|
for i in sensors[key]:
|
||||||
if json_data.get(i)['type'] == 'ZLLPresence':
|
if not battery:
|
||||||
print(f"{json_data.get(i)['name']} ({json_data.get(i)['config']['battery']}%)")
|
if json_data.get(i)['type'] == 'ZLLPresence':
|
||||||
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
print(f"{json_data.get(i)['name']:<32s} ({json_data.get(i)['config']['battery']}%)")
|
||||||
if json_data.get(i)['type'] == 'ZLLLightLevel':
|
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
||||||
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
if json_data.get(i)['type'] == 'ZLLLightLevel':
|
||||||
if json_data.get(i)['type'] == 'ZLLTemperature':
|
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
||||||
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
if json_data.get(i)['type'] == 'ZLLTemperature':
|
||||||
|
print(f"{i:>5s}: {json_data.get(i)['productname']}")
|
||||||
|
else:
|
||||||
|
if int(json_data.get(i)['config']['battery']) < battery:
|
||||||
|
if json_data.get(i)['type'] == 'ZLLPresence':
|
||||||
|
print(f"{json_data.get(i)['name']:<32s} battery level {json_data.get(i)['config']['battery']}%")
|
||||||
|
|
Loading…
Reference in New Issue