command line programs to control broadlink devices
This commit is contained in:
parent
846cc35366
commit
76dd4cfc70
2 changed files with 84 additions and 0 deletions
59
cli/broadlink_cli
Executable file
59
cli/broadlink_cli
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import broadlink
|
||||
import sys
|
||||
import argparse
|
||||
import time
|
||||
|
||||
def auto_int(x):
|
||||
return int(x, 0)
|
||||
|
||||
parser = argparse.ArgumentParser(fromfile_prefix_chars='@');
|
||||
parser.add_argument("--device", help="device definition as 'type host mac'")
|
||||
parser.add_argument("--type", type=auto_int, default=0x2712, help="type of device")
|
||||
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("--send", help="send command")
|
||||
parser.add_argument("--learn",action="store_true", help="learn command")
|
||||
parser.add_argument("--learnfile", help="learn command and save to specified file")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.device:
|
||||
values = args.device.split();
|
||||
type = int(values[0],0)
|
||||
host = values[1]
|
||||
mac = bytearray.fromhex(values[2])
|
||||
else:
|
||||
type = args.type
|
||||
host = args.host
|
||||
mac = bytearray.fromhex(args.mac)
|
||||
|
||||
|
||||
dev = broadlink.gendevice(type, (host, 80), mac)
|
||||
dev.auth()
|
||||
if args.temperature:
|
||||
print dev.check_temperature()
|
||||
if args.send:
|
||||
data = bytearray.fromhex(args.send)
|
||||
dev.send_data(data)
|
||||
if args.learn or args.learnfile:
|
||||
dev.enter_learning()
|
||||
data = None
|
||||
print "Learning..."
|
||||
timeout = 30
|
||||
while (data is None) and (timeout > 0):
|
||||
time.sleep(2)
|
||||
timeout -= 2
|
||||
data = dev.check_data()
|
||||
if data:
|
||||
learned = ''.join(format(x, '02x') for x in bytearray(data))
|
||||
if args.learn:
|
||||
print learned
|
||||
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..."
|
||||
|
25
cli/broadlink_discovery
Executable file
25
cli/broadlink_discovery
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import broadlink
|
||||
import time
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(fromfile_prefix_chars='@');
|
||||
parser.add_argument("--timeout", type=int, default=5, help="timeout to wait for receiving discovery responses")
|
||||
args = parser.parse_args()
|
||||
|
||||
print "discover"
|
||||
devices = broadlink.discover(timeout=args.timeout)
|
||||
#print devices
|
||||
for device in devices:
|
||||
if device.auth():
|
||||
print "###########################################"
|
||||
# print device
|
||||
print device.type
|
||||
print "# broadlink_cli --type 0x2712 --host {} --mac {}".format(device.host[0], ''.join(format(x, '02x') for x in device.mac))
|
||||
print "Device file data (to be used with --device @filename in broadlink_cli) : "
|
||||
print "0x2712 {} {}".format(device.host[0], ''.join(format(x, '02x') for x in device.mac))
|
||||
print "temperature = {}".format(device.check_temperature())
|
||||
print ""
|
||||
else:
|
||||
print "Error authenticating with device : {}".format(device.host)
|
Loading…
Reference in a new issue