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

fixed learnfile switch and python3 compatibility (#247)

This commit is contained in:
AnilDaoud 2019-05-23 21:13:14 +08:00 committed by Daniel Høyer Iversen
parent ef66997953
commit 45e26fda23

View File

@ -4,6 +4,8 @@ import broadlink
import sys
import argparse
import time
import base64
import codecs
TICK = 32.84
IR_TOKEN = 0x26
@ -120,7 +122,7 @@ if args.send:
data = durations_to_broadlink(parse_durations(' '.join(args.data))) \
if args.durations else bytearray.fromhex(''.join(args.data))
dev.send_data(data)
if args.learn:
if args.learn or args.learnfile:
dev.enter_learning()
data = None
print("Learning...")
@ -135,7 +137,8 @@ if args.learn:
else ''.join(format(x, '02x') for x in bytearray(data))
if args.learn:
print(learned)
print("Base64: " + base64.b64encode(learned.decode("hex")))
decode_hex = codecs.getdecoder("hex_codec")
print("Base64: " + str(base64.b64encode(decode_hex(learned)[0])))
if args.learnfile:
print("Saving to {}".format(args.learnfile))
with open(args.learnfile, "w") as text_file: