diff options
Diffstat (limited to 'cli/broadlink_cli')
-rwxr-xr-x | cli/broadlink_cli | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/cli/broadlink_cli b/cli/broadlink_cli index 1ff45f1d9b3c..989c6c118ba7 100755 --- a/cli/broadlink_cli +++ b/cli/broadlink_cli @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import broadlink +import sys import argparse import time @@ -67,11 +68,19 @@ parser.add_argument("--type", type=auto_int, default=0x2712, help="type of devic parser.add_argument("--host", help="host address") parser.add_argument("--mac", help="mac address (hex reverse), as used by python-broadlink library") parser.add_argument("--temperature",action="store_true", help="request temperature from device") +parser.add_argument("--energy",action="store_true", help="request energy consumption from device") +parser.add_argument("--check", action="store_true", help="check current power state") +parser.add_argument("--checknl", action="store_true", help="check current nightlight state") +parser.add_argument("--turnon", action="store_true", help="turn on device") +parser.add_argument("--turnoff", action="store_true", help="turn off device") +parser.add_argument("--turnnlon", action="store_true", help="turn on nightlight on the device") +parser.add_argument("--turnnloff", action="store_true", help="turn off nightlight on the device") +parser.add_argument("--switch", action="store_true", help="switch state from on to off and off to on") parser.add_argument("--send", action="store_true", help="send command") parser.add_argument("--sensors", action="store_true", help="check all sensors") parser.add_argument("--learn", action="store_true", help="learn command") -parser.add_argument("--learnfile", help="save learned command to a specified file") parser.add_argument("--rfscanlearn", action="store_true", help="rf scan learning") +parser.add_argument("--learnfile", help="save learned command to a specified file") parser.add_argument("--durations", action="store_true", help="use durations in micro seconds instead of the Broadlink format") parser.add_argument("--convert", action="store_true", help="convert input data to durations") parser.add_argument("data", nargs='*', help="Data to send or convert") @@ -79,7 +88,7 @@ args = parser.parse_args() if args.device: values = args.device.split() - type = int(values[0], 0) + type = int(values[0],0) host = values[1] mac = bytearray.fromhex(values[2]) elif args.mac: @@ -87,7 +96,7 @@ elif args.mac: host = args.host mac = bytearray.fromhex(args.mac) -if args.host or host is not None: +if args.host or args.device: dev = broadlink.gendevice(type, (host, 80), mac) dev.auth() @@ -97,6 +106,8 @@ if args.convert: print(format_durations(durations)) if args.temperature: print(dev.check_temperature()) +if args.energy: + print(dev.get_energy()) if args.sensors: try: data = dev.check_sensors() @@ -122,14 +133,55 @@ if args.learn: learned = format_durations(to_microseconds(bytearray(data))) \ if args.durations \ else ''.join(format(x, '02x') for x in bytearray(data)) - if args.learnfile is None: + if args.learn: print(learned) - if args.learnfile is not None: + if args.learnfile: print("Saving to {}".format(args.learnfile)) with open(args.learnfile, "w") as text_file: text_file.write(learned) else: print("No data received...") +if args.check: + if dev.check_power(): + print('* ON *') + else: + print('* OFF *') +if args.checknl: + if dev.check_nightlight(): + print('* ON *') + else: + print('* OFF *') +if args.turnon: + dev.set_power(True) + if dev.check_power(): + print('== Turned * ON * ==') + else: + print('!! Still OFF !!') +if args.turnoff: + dev.set_power(False) + if dev.check_power(): + print('!! Still ON !!') + else: + print('== Turned * OFF * ==') +if args.turnnlon: + dev.set_nightlight(True) + if dev.check_nightlight(): + print('== Turned * ON * ==') + else: + print('!! Still OFF !!') +if args.turnnloff: + dev.set_nightlight(False) + if dev.check_nightlight(): + print('!! Still ON !!') + else: + print('== Turned * OFF * ==') +if args.switch: + if dev.check_power(): + dev.set_power(False) + print('* Switch to OFF *') + else: + dev.set_power(True) + print('* Switch to ON *') if args.rfscanlearn: dev.sweep_frequency() print("Learning RF Frequency, press and hold the button to learn...") @@ -174,4 +226,4 @@ if args.rfscanlearn: with open(args.learnfile, "w") as text_file: text_file.write(learned) else: - print("No data received...") \ No newline at end of file + print("No data received...") |