Skip to content

Commit

Permalink
Fix --learn base64 to not crash with --durations
Browse files Browse the repository at this point in the history
Also remove its b'...' wrapping.
  • Loading branch information
wgrant authored and felipediel committed Apr 10, 2024
1 parent 50be543 commit 36e9bed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions broadlink/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@


def durations_to_ir_data(durations) -> None:
"""Convert a microsecond duration sequence into a Broadlink IR packet
This can then be passed into send_data.
"""
result = bytearray()
result.append(IR_TOKEN)
result.append(0)
Expand All @@ -25,6 +29,10 @@ def durations_to_ir_data(durations) -> None:


def data_to_durations(bytes):
"""Parse a Broadlink packet into a microsecond duration sequence
Supports both IR and RF.
"""
result = []
# XXX: Should check IR/RF token, repeat and length bytes.
index = 4
Expand Down
8 changes: 4 additions & 4 deletions cli/broadlink_cli
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ if args.learn or (args.learnfile and not args.rflearn):
print("No data received...")
exit(1)

learned = format_durations(data_to_durations(bytearray(data))) \
learned_str = format_durations(data_to_durations(bytearray(data))) \
if args.durations \
else ''.join(format(x, '02x') for x in bytearray(data))
if args.learn:
print(learned)
print(learned_str)
decode_hex = codecs.getdecoder("hex_codec")
print("Base64: " + str(base64.b64encode(decode_hex(learned)[0])))
print("Base64: " + base64.b64encode(data).decode('ascii'))
if args.learnfile:
print("Saving to {}".format(args.learnfile))
with open(args.learnfile, "w") as text_file:
text_file.write(learned)
text_file.write(learned_str)
if args.check:
if dev.check_power():
print('* ON *')
Expand Down

0 comments on commit 36e9bed

Please sign in to comment.