From 554d1ff1cfa186524795958b76191e76d0d7a7c5 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 20 Dec 2020 04:04:55 -0600 Subject: Fix stop_repeat bug, default connection to None, and update docstrings --- lirc/client.py | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/lirc/client.py b/lirc/client.py index 9b55fba..f34f9af 100644 --- a/lirc/client.py +++ b/lirc/client.py @@ -1,4 +1,5 @@ from typing import List, Union +from pathlib import Path from .connection.lircd_connection import LircdConnection from .exceptions import LircdCommandFailureError @@ -8,7 +9,7 @@ from .reply_packet_parser import ReplyPacketParser class Client: """Communicate with the lircd daemon.""" - def __init__(self, connection: LircdConnection = LircdConnection()) -> None: + def __init__(self, connection: LircdConnection = None) -> None: """ Initialize the client by connecting to the lircd socket. @@ -20,13 +21,16 @@ class Client: ValueError: If connection is not an instance of LircdConnection. LircdConnectionError: If the socket cannot connect to the address. """ + if not connection: + connection = LircdConnection() + + if not isinstance(connection, LircdConnection): + raise ValueError("`connection` must be an instance of `LircdConnection`") + # Used for start_repeat and stop_repeat self.__last_send_start_remote = None self.__last_send_start_key = None - if not isinstance(connection, LircdConnection): - raise ValueError("`connection` must be an instance of `LircdConnection`") - self.__connection = connection self.__connection.connect() @@ -110,10 +114,10 @@ class Client: Raises: LircdCommandFailure: If the command fails. """ - if self.__last_send_start_remote: + if not remote and self.__last_send_start_remote: remote = self.__last_send_start_remote - if self.__last_send_start_key: + if not key and self.__last_send_start_key: key = self.__last_send_start_key self.__send_command(f"SEND_STOP {remote} {key}") @@ -146,11 +150,14 @@ class Client: """ return self.__send_command(f"LIST {remote}") - def start_logging(self, path: str) -> None: + def start_logging(self, path: Union[str, Path]) -> None: """ Send a lircd SET_INPUTLOG command which sets the path to log all lircd received data to. + Args: + path: The path to start logging lircd recieved data to. + Raises: LircdCommandFailure: If the command fails. """ @@ -183,6 +190,10 @@ class Client: """ Set driver-specific option named key to given value. + Args: + key: The key to set for the driver. + value: The value for the key to set. + Raises: LircdCommandFailure: If the command fails. """ @@ -192,9 +203,25 @@ class Client: self, remote: str, key: str, repeat_count: int = 1, keycode: int = 0 ) -> None: """ + Simulate an IR event. + The --allow-simulate command line option to `lircd` must be active for this command not to fail. + Example Format: +