diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-20 04:06:59 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-20 04:06:59 -0600 |
| commit | 7797d71fa25c0c94627b156bce971c8208a7b287 (patch) | |
| tree | 54c210ca6ada1d940f3c3b7338e21303e53dbc52 | |
| parent | Add docstrings to default connection (diff) | |
| download | lirc-7797d71fa25c0c94627b156bce971c8208a7b287.zip | |
Remove socket property and update docstrings
| -rw-r--r-- | lirc/connection/abstract_connection.py | 5 | ||||
| -rw-r--r-- | lirc/connection/lircd_connection.py | 32 |
2 files changed, 23 insertions, 14 deletions
diff --git a/lirc/connection/abstract_connection.py b/lirc/connection/abstract_connection.py index ca855a6..3edc89b 100644 --- a/lirc/connection/abstract_connection.py +++ b/lirc/connection/abstract_connection.py @@ -22,11 +22,6 @@ class AbstractConnection(ABC): @property @abstractmethod - def socket(self) -> socket.socket: - pass - - @property - @abstractmethod def address(self) -> Union[str, tuple]: pass diff --git a/lirc/connection/lircd_connection.py b/lirc/connection/lircd_connection.py index baa7d57..8002204 100644 --- a/lirc/connection/lircd_connection.py +++ b/lirc/connection/lircd_connection.py @@ -1,4 +1,4 @@ -import socket as stdlib_socket +import socket from collections import deque from typing import Union @@ -10,8 +10,8 @@ from .default_connection import DefaultConnection class LircdConnection(AbstractConnection): def __init__( self, - address: Union[str, tuple] = DefaultConnection().address, - socket: stdlib_socket.socket = DefaultConnection().socket, + address: Union[str, tuple] = None, + socket: socket.socket = None, timeout: float = 5.0, ): """ @@ -40,6 +40,14 @@ class LircdConnection(AbstractConnection): timeout: The amount of time to wait for data from the socket before we timeout. """ + default = DefaultConnection() + + if address is None: + address = default.address + + if socket is None: + socket = default.socket + self.__buffer = deque() self.__buffer_size = 4096 self.__address = address @@ -65,11 +73,14 @@ class LircdConnection(AbstractConnection): raise LircdConnectionError(error) @property - def socket(self) -> stdlib_socket.socket: - return self.__socket - - @property def address(self) -> str: + """ + Retrieve the address that this lircd connection + is connected to. + + Returns: + The current address being used. + """ return self.__address def close(self): @@ -82,6 +93,9 @@ class LircdConnection(AbstractConnection): """ Send a commend to the lircd socket connection. + Args: + data: The data to send to the lircd socket. + Raises: TypeError: if data is not a string. """ @@ -132,12 +146,12 @@ class LircdConnection(AbstractConnection): self.__buffer.append(packet.decode("utf-8")) return self.__buffer.popleft() - except stdlib_socket.timeout: + except socket.timeout: raise TimeoutError( "could not find any data on the socket after " f"{self.__socket.gettimeout()} seconds, socket timed out." ) - except stdlib_socket.error as error: + except socket.error as error: raise LircdSocketError( f"An error occurred while reading from the lircd socket: {error}" ) |