about summary refs log tree commit diff
path: root/cli/broadlink_cli
diff options
context:
space:
mode:
authorAnilDaoud <anil@via.ecp.fr>2019-05-23T13·13+0800
committerDaniel Høyer Iversen <mail@dahoiv.net>2019-05-23T13·13+0200
commit45e26fda237441777d76f5b7362c84ce9f757c89 (patch)
treea8fb27179181942c653a0afa88994134e8d749ad /cli/broadlink_cli
parentef66997953cb2beb05e05b81096b04a79d0f59ec (diff)
fixed learnfile switch and python3 compatibility (#247)
Diffstat (limited to 'cli/broadlink_cli')
-rwxr-xr-xcli/broadlink_cli7
1 files changed, 5 insertions, 2 deletions
diff --git a/cli/broadlink_cli b/cli/broadlink_cli
index 1c3e231d69e5..1a8fe5703468 100755
--- a/cli/broadlink_cli
+++ b/cli/broadlink_cli
@@ -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: