API Specification
- class lirc.Client(connection: type[AbstractConnection] | None = None)
Bases:
objectCommunicate with the lircd daemon.
- __init__(connection: type[AbstractConnection] | None = None) None
Initialize the client by connecting to the lircd socket.
- Parameters:
connection – The connection to lircd. Created with defaults
provided. (depending on the operating system if one is not)
- Raises:
TypeError – If connection is not an instance of AbstractConnection.
LircdConnectionError – If the socket cannot connect to the address.
- close() None
Close the connection to the socket.
- driver_option(key: str, value: str) None
Set driver-specific option named key to given value.
- Parameters:
key – The key to set for the driver.
value – The value for the key to set.
- Raises:
LircdCommandFailure – If the command fails.
- list_remote_keys(remote: str) list[str]
List all the keys for a specific remote.
- Parameters:
remote – The remote to list the keys of.
- Raises:
LircdCommandFailure – If the command fails.
- Returns:
The list of keys from the remote.
- list_remotes() list[str]
List all the remotes that lirc has in its
/etc/lirc/lircd.conf.dfolder.- Raises:
LircdCommandFailure – If the command fails.
- Returns:
The list of all remotes.
- send_once(remote: str, key: str, repeat_count: int = 0) None
Send an lircd SEND_ONCE command.
- Parameters:
key – The name of the key to send.
remote – The remote to use keys from.
repeat_count – The number of times to repeat this key. If this is set to 1, that means this key will be sent twice (repeated once).
Changed in version 2.0.0: The repeat_count parameter has been changed to have a default value of 0 instead of 1. This ensures send_once only sends 1 IR signal instead of sending 1 and then repeating it (therefore, 2 signals).
- Raises:
LircdCommandFailure – If the command fails.
- send_start(remote: str, key: str) None
Send an lircd SEND_START command.
This will repeat the given key until send_stop is called.
- Parameters:
remote – The remote to use keys from.
key – The name of the key to start sending.
- Raises:
LircdCommandFailure – If the command fails.
- send_stop(remote: str = '', key: str = '') None
Send an lircd SEND_STOP command.
The remote and key default to the remote and key last used with
send_startif they are not specified, since the most likely use case is sending asend_startand then asend_stop.- Parameters:
remote – The remote to stop.
key – The key to stop sending.
- Raises:
LircdCommandFailure – If the command fails.
- set_transmitters(transmitters: int | list[int]) None
Set the active transmitters.
Example
>>> import lirc >>> client = lirc.Client() >>> client.set_transmitters(1) >>> client.set_transmitters([1,3,5])
- Parameters:
transmitters – The transmitters to set active.
- Raises:
LircdCommandFailure – If the command fails.
- simulate(remote: str, key: str, repeat_count: int = 0, keycode: int = 0) None
Simulate an IR event.
The
--allow-simulatecommand line option to lircd must be active for this command not to fail.- Lircd Format:
<code> <repeat count> <button name> <remote control name>
Example
0000000000f40bf0 00 KEY_UP ANIMAX
- Parameters:
remote – The remote to simulate key presses from.
key – The key on the remote to simulate.
repeat_count – The number of times to repeat the simulated key press.
keycode – lircd(8) describes this option as a 16 hexadecimal digit number encoding of the IR signal. However, it says it is depreciated and should be ignored.
Changed in version 3.0.0: The repeat_count parameter has been changed to have a default value of 0 instead of 1. The previous value was incorrect since it leads to the command being sent twice (1 and then repeated once).
- Raises:
LircdCommandFailure – If the command fails.
- start_logging(path: str | Path) None
Send a lircd SET_INPUTLOG command which sets the path to log all lircd received data to.
- Parameters:
path – The path to start logging lircd recieved data to.
- Raises:
LircdCommandFailure – If the command fails.
- stop_logging() None
Stop logging to the inputlog path from start_logging.
- Raises:
LircdCommandFailure – If the command fails.
- version() str
Retrieve the version of LIRC
- Raises:
LircdCommandFailure – If the command fails.
- Returns:
The version of LIRC being used.
- class lirc.LircdConnection(address: str | tuple = None, socket: socket = None, timeout: float = 5.0)
Bases:
AbstractConnection- __init__(address: str | tuple = None, socket: socket = None, timeout: float = 5.0)
Initialize the LircdConnection. This sets up state we’ll need, but it does not connect to that socket. To connect, we can call connect() after initialization.
- Parameters:
address – The address to the socket. Defaults to different values depending on the host operating system. On Linux, it defaults to
/var/run/lirc/lircd. On Windows, a tuple of("localhost", 8765). And on Darwin (macOS),/opt/local/var/run/lirc/lircd.socket – The socket to use to connect to lircd. The default socket is determined using the host operating system. For Linux and Darwin, a unix domain socket connection is used i.e.
socket.socket(socket.AF_UNIX, socket.SOCK_STREAM). However on Windows, a TCP socket is used i.e.socket.socket(socket.AF_INET, socket.SOCK_STREAM).timeout – The amount of time to wait for data from the socket before we timeout.
- property address: str
Retrieve the address that this lircd connection is connected to.
- Returns:
The current address being used.
- close()
Closes the socket connection.
- connect()
Connect to the socket at the address both specified on init.
- Raises:
LircdConnectionError – If the address is invalid or lircd is not running.
- readline() str
Read a line of data from the lircd socket.
We read 4096 bytes at a time as the buffer size. Therefore after data is read from the socket, all the lines are stored in a buffer if there is more than 1 and subsequent calls grab a line that stored in that buffer until it is empty. Then, another call to the socket would be made.
- Raises:
TimeoutError – If we are not able to grab data from the socket in a specified amount of time (the initial timeout time on initialization).
LircdSocketError – If some other error happened when trying to read from the socket.
- Returns:
A line from the lircd socket.
- send(data: str)
Send a commend to the lircd socket connection.
- Parameters:
data – The data to send to the lircd socket.
- Raises:
TypeError – if data is not a string.