mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.35k stars 477 forks source link

--durations broken in current version #740

Closed bengtmartensson closed 2 months ago

bengtmartensson commented 1 year ago

I implemented --durations in #105. Unfortunately, in the current version it does not work. When used with --send a division goes wrong, interrupting the execution, since the current Python seems to require // to divide integers.

./broadlink_cli --device @device --send --durations +9024 -4512 +564 -1692 +564 -564 +564 -564 +564 -1692 +564 -564 +564 -564 +564 -1692 +564 -564 +564 -564 +564 -1692 +564 -1692 +564 -564 +564 -1692 +564 -1692 +564 -564 +564 -1692 +564 -1692 +564 -1692 +564 -564 +564 -1692 +564 -1692 +564 -564 +564 -564 +564 -564 +564 -564 +564 -564 +564 -1692 +564 -564 +564 -564 +564 -1692 +564 -1692 +564 -1692 +564 -39756 +9024 -2256 +564 -96156
Traceback (most recent call last):
  File "/home/bengt/harctoolbox/python-broadlink/cli/./broadlink_cli", line 127, in <module>
    data = durations_to_broadlink(parse_durations(' '.join(args.data))) \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bengt/harctoolbox/python-broadlink/cli/./broadlink_cli", line 42, in durations_to_broadlink
    result.append(len(durations) / 256)
TypeError: 'float' object cannot be interpreted as an integer

When --learning, there is a --- strictly speaking harmless (but highly confusing) --- error:

$ ./broadlink_cli --device @device --learn --durations
Learning...
+9688 -4860 +591 -591 +624 -591 +591 -624 +591 -624 +591 -624 +591 -591 +624 -591 +591 -1839 +591 -1839 +591 -1806 +624 -1806 +591 -1839 +591 -1806 +624 -1806 +591 -1839 +591 -1806 +624 -1806 +591 -624 +591 -624 +591 -591 +624 -591 +591 -624 +591 -624 +591 -624 +591 -591 +624 -1806 +591 -1839 +591 -1806 +624 -1806 +591 -1839 +591 -1839 +591 -1806 +591 -41805 +9688 -2397 +624 -103446 +9688 -2397 +657 -103413 +9721 -2397 +624 -109456
Traceback (most recent call last):
  File "/home/bengt/harctoolbox/python-broadlink/cli/./broadlink_cli", line 152, in <module>
    print("Base64: " + str(base64.b64encode(decode_hex(learned)[0])))
                                            ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/encodings/hex_codec.py", line 19, in hex_decode
    return (binascii.a2b_hex(input), len(input))
            ^^^^^^^^^^^^^^^^^^^^^^^
binascii.Error: Odd-length string

I plan to submit a fix shortly.