Menu

#353 Bug in SendCommand in client.py

0.10.2
closed
nobody
None
na
2025-07-01
2019-11-24
No

There appears to be a bug in the SendCommand class in client.py for the python bindings (I'm using python 3 if it matters).

The entire class is (around line 600 or so):

class SendCommand(Command):
     ''' Send given key, see SEND_ONCE in lircd(8) manpage. '''

     def __init__(self, connection: AbstractConnection, remote: str, keys: str):
         if not len(keys):
             raise ValueError('No keys to send given')
         cmd = 'SEND_ONCE %s %s\n' % (remote, ' '.join(keys))
         Command.__init__(self, cmd, connection)

Notice the "keys" argument is a string. However, it's used as the argument to "join", which results in each character of the supplied value between split with spaces inbetween each character. When trying to use this to, for instance, send the key "KEY_POWER", it results in an error from LIRC: unknown command: "K"

The man page for lircd doesn't indicate multple buttons may be provided with SEND_ONCE, so it seems the simple fix is to remove the use of "join" and just provide "keys" directly.

Also, there's no way to specify "repeats" so perhaps another, optional argument could be added for that.

Discussion

  • Bengt Martensson

    First some facts:

    1. man irsend says irsend [options] send_once <remote> <code> [code...], so it does send several commands,
    2. The documentation string indicates only one ("given key"), contradicting 1,
    3. join operates on an Iterable, so calling with an array of strings gives the desired result; with a string, it gives the result you describe (because a str is an Iterable on characters ).

    So clarifying the documentation ("should be called with an array of strings (or Iterable over strings)") would be alternative.

    Finally, let me remark that I, with some cooperation with Alec, have written "Lirconian", a pure Python implementation of irsend, usable as API and as command line program. (It supports repeats, but not multiple commands.) It is available on PyPi and on Github. Please try it out. Why invoke compiled, architecture dependent libraries for what you can do with pure Python?

     
  • Sean Young

    Sean Young - 2024-11-13

    The ' '.join(keys) indicates that it is a list. Also, the parameter is called keys and not key.

    Also when you look at lirctool.py, it's a clearly a list there. I think the documentation string and type hint is wrong.

     
  • Sean Young

    Sean Young - 2025-07-01
    • status: open --> closed
     
  • Sean Young

    Sean Young - 2025-07-01

    Fix in commit ae278ac63b6ec4c322752ca6631645465a6c41e9

     

Log in to post a comment.

MongoDB Logo MongoDB