summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2021-11-28 17:33:53 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2021-11-28 17:33:53 -0600
commite955eccf80752d269dcd2031d71f7a9d9199201a (patch)
tree6932c9b554231c6f340a62ffec9b7bff00229c76
parentUpdate pre-commit hooks (diff)
downloadlirc-e955eccf80752d269dcd2031d71f7a9d9199201a.zip
Allow `connection` to be any AbstractConnection
-rw-r--r--CHANGELOG.rst25
-rw-r--r--lirc/client.py11
-rw-r--r--tests/test_client.py6
3 files changed, 26 insertions, 16 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 6e7fdf6..96fdd08 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -7,6 +7,15 @@ The format is based on `Keep a
Changelog <https://keepachangelog.com/en/1.0.0/>`_, and this project
adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
+Unreleased
+------------------
+
+**Fixed**
+
+- `lirc.Client` will throw a `TypeError` only if the passed `connection`
+ is not an instance of `AbstractConnection`. Previously, it would throw
+ a `TypeError` if `connection` was not an `LircdConnection`.
+
2.0.0 - 2021-04-18
------------------
@@ -16,13 +25,13 @@ adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
an IR code twice by default. This is because the ``repeat_count`` keyword argument
was set to 1 instead of 0, causing it to send the initial IR code and repeat it once.
This now defaults to 0.
-
+
On v1, this can be worked around by explicitly specifying the ``repeat_count`` to only send 1 IR signal by setting it to 0:
-
+
.. code-block:: python
-
+
import lirc
-
+
client = lirc.Client()
client.send_once('remote', 'key', repeat_count=0)
@@ -30,14 +39,14 @@ adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.
``/opt/run/var/run/lirc/lircd`` when it should have been
``/opt/local/var/run/lirc/lircd``. This is unlikely to have
an impact since the previous default directory was incorrect.
-
+
On v1 and on macOS, this can also be worked around by explicitly specifying the connection path rather
than relying on the default.
-
+
.. code-block:: python
-
+
import lirc
-
+
client = lirc.Client(
connection=lirc.LircdConnection(
address="/opt/local/var/run/lirc/lircd",
diff --git a/lirc/client.py b/lirc/client.py
index 84b98c9..b659c00 100644
--- a/lirc/client.py
+++ b/lirc/client.py
@@ -1,6 +1,7 @@
from pathlib import Path
-from typing import List, Union
+from typing import List, Type, Union
+from .connection.abstract_connection import AbstractConnection
from .connection.lircd_connection import LircdConnection
from .exceptions import LircdCommandFailureError
from .reply_packet_parser import ReplyPacketParser
@@ -9,7 +10,7 @@ from .reply_packet_parser import ReplyPacketParser
class Client:
"""Communicate with the lircd daemon."""
- def __init__(self, connection: LircdConnection = None) -> None:
+ def __init__(self, connection: Type[AbstractConnection] = None) -> None:
"""
Initialize the client by connecting to the lircd socket.
@@ -18,14 +19,14 @@ class Client:
depending on the operating system if one is not provided.
Raises:
- TypeError: If connection is not an instance of LircdConnection.
+ TypeError: If connection is not an instance of AbstractConnection.
LircdConnectionError: If the socket cannot connect to the address.
"""
if not connection:
connection = LircdConnection()
- if not isinstance(connection, LircdConnection):
- raise TypeError("`connection` must be an instance of `LircdConnection`")
+ if not isinstance(connection, AbstractConnection):
+ raise TypeError("`connection` must be an instance of `AbstractConnection`")
# Used for start_repeat and stop_repeat
self.__last_send_start_remote = None
diff --git a/tests/test_client.py b/tests/test_client.py
index 237a038..e7b80d5 100644
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -20,19 +20,19 @@ def test_that_custom_connections_can_be_used(mock_socket):
assert client._Client__connection == connection
-def test_that_custom_connection_that_is_not_a_lircd_connection_raises_error(
+def test_that_custom_connection_that_is_not_an_abstract_connection_raises_error(
mock_connection,
):
"""
lirc.Client.__init__
Ensure that passing in something that is not an instance of
- LircdConnection raise a TypeError.
+ AbstractConnection raises a TypeError.
"""
with pytest.raises(TypeError) as error:
Client(connection=Client(connection=mock_connection)) # SUT
- assert "must be an instance of `LircdConnection`" in str(error)
+ assert "must be an instance of `AbstractConnection`" in str(error)
def test_that_no_connection_passed_in_creates_default_one():