1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-22 15:10:12 +01:00

broadlink_cli: python3 support

This commit is contained in:
Pim van den Berg 2019-01-16 09:34:20 +01:00
parent 1cceae73eb
commit c393cf6079

View File

@ -102,11 +102,11 @@ if args.host or args.device:
if args.convert: if args.convert:
data = bytearray.fromhex(''.join(args.data)) data = bytearray.fromhex(''.join(args.data))
durations = to_microseconds(data) durations = to_microseconds(data)
print format_durations(durations) print(format_durations(durations))
if args.temperature: if args.temperature:
print dev.check_temperature() print(dev.check_temperature())
if args.energy: if args.energy:
print dev.get_energy() print(dev.get_energy())
if args.sensors: if args.sensors:
try: try:
data = dev.check_sensors() data = dev.check_sensors()
@ -114,7 +114,7 @@ if args.sensors:
data = {} data = {}
data['temperature'] = dev.check_temperature() data['temperature'] = dev.check_temperature()
for key in data: for key in data:
print "{} {}".format(key, data[key]) print("{} {}".format(key, data[key]))
if args.send: if args.send:
data = durations_to_broadlink(parse_durations(' '.join(args.data))) \ data = durations_to_broadlink(parse_durations(' '.join(args.data))) \
if args.durations else bytearray.fromhex(''.join(args.data)) if args.durations else bytearray.fromhex(''.join(args.data))
@ -122,7 +122,7 @@ if args.send:
if args.learn or args.learnfile: if args.learn or args.learnfile:
dev.enter_learning() dev.enter_learning()
data = None data = None
print "Learning..." print("Learning...")
timeout = 30 timeout = 30
while (data is None) and (timeout > 0): while (data is None) and (timeout > 0):
time.sleep(2) time.sleep(2)
@ -133,51 +133,51 @@ if args.learn or args.learnfile:
if args.durations \ if args.durations \
else ''.join(format(x, '02x') for x in bytearray(data)) else ''.join(format(x, '02x') for x in bytearray(data))
if args.learn: if args.learn:
print learned print(learned)
if args.learnfile: if args.learnfile:
print "Saving to {}".format(args.learnfile) print("Saving to {}".format(args.learnfile))
with open(args.learnfile, "w") as text_file: with open(args.learnfile, "w") as text_file:
text_file.write(learned) text_file.write(learned)
else: else:
print "No data received..." print("No data received...")
if args.check: if args.check:
if dev.check_power(): if dev.check_power():
print '* ON *' print('* ON *')
else: else:
print '* OFF *' print('* OFF *')
if args.checknl: if args.checknl:
if dev.check_nightlight(): if dev.check_nightlight():
print '* ON *' print('* ON *')
else: else:
print '* OFF *' print('* OFF *')
if args.turnon: if args.turnon:
dev.set_power(True) dev.set_power(True)
if dev.check_power(): if dev.check_power():
print '== Turned * ON * ==' print('== Turned * ON * ==')
else: else:
print '!! Still OFF !!' print('!! Still OFF !!')
if args.turnoff: if args.turnoff:
dev.set_power(False) dev.set_power(False)
if dev.check_power(): if dev.check_power():
print '!! Still ON !!' print('!! Still ON !!')
else: else:
print '== Turned * OFF * ==' print('== Turned * OFF * ==')
if args.turnnlon: if args.turnnlon:
dev.set_nightlight(True) dev.set_nightlight(True)
if dev.check_nightlight(): if dev.check_nightlight():
print '== Turned * ON * ==' print('== Turned * ON * ==')
else: else:
print '!! Still OFF !!' print('!! Still OFF !!')
if args.turnnloff: if args.turnnloff:
dev.set_nightlight(False) dev.set_nightlight(False)
if dev.check_nightlight(): if dev.check_nightlight():
print '!! Still ON !!' print('!! Still ON !!')
else: else:
print '== Turned * OFF * ==' print('== Turned * OFF * ==')
if args.switch: if args.switch:
if dev.check_power(): if dev.check_power():
dev.set_power(False) dev.set_power(False)
print '* Switch to OFF *' print('* Switch to OFF *')
else: else:
dev.set_power(True) dev.set_power(True)
print '* Switch to ON *' print('* Switch to ON *')