added -b option for battery test only to use with cron

This commit is contained in:
mischa 2019-11-06 20:19:05 +01:00
parent eb78856c45
commit 1dd8b4e202
1 changed files with 16 additions and 7 deletions

View File

@ -26,11 +26,15 @@ import collections
parser = argparse.ArgumentParser(description="Get all sensor 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("-b", "--battery", type=int, help="battery check only, threshold, default 20")
parser.add_argument("-v", "--verbose", action='store_true', help="verbose")
try:
args = parser.parse_args()
bridge = args.bridge
token = args.token
battery = args.battery
verbose = args.verbose
except argparse.ArgumentError as e:
print(str(e))
@ -58,10 +62,15 @@ for key in json_data:
for key in sensors:
for i in sensors[key]:
if json_data.get(i)['type'] == 'ZLLPresence':
print(f"{json_data.get(i)['name']} ({json_data.get(i)['config']['battery']}%)")
print(f"{i:>5s}: {json_data.get(i)['productname']}")
if json_data.get(i)['type'] == 'ZLLLightLevel':
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']}")
if not battery:
if json_data.get(i)['type'] == 'ZLLPresence':
print(f"{json_data.get(i)['name']:<32s} ({json_data.get(i)['config']['battery']}%)")
print(f"{i:>5s}: {json_data.get(i)['productname']}")
if json_data.get(i)['type'] == 'ZLLLightLevel':
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']}%")