diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-26 15:12:03 -0600 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2020-12-26 15:12:03 -0600 |
| commit | 25f3a68f39a9618549ea1fbe7c7b06dd7306af8b (patch) | |
| tree | 7327fa82a848c568437f244389180fb6ce8a82b4 | |
| parent | Add reply packet parser tests (diff) | |
| download | lirc-25f3a68f39a9618549ea1fbe7c7b06dd7306af8b.zip | |
Rename send, start_repeat, and stop_repeat
This now aligns exactly with the calls to lircd.
| -rw-r--r-- | README.rst | 8 | ||||
| -rw-r--r-- | docs/source/usage.rst | 8 | ||||
| -rw-r--r-- | lirc/client.py | 8 | ||||
| -rw-r--r-- | tests/test_client.py | 34 |
4 files changed, 29 insertions, 29 deletions
@@ -109,11 +109,11 @@ Sending IR import lirc client = lirc.Client() - client.send("my-remote-name", "KEY_POWER") - client.send("my-remote-name", "KEY_3", repeat_count=2) + client.send_once("my-remote-name", "KEY_POWER") + client.send_once("my-remote-name", "KEY_3", repeat_count=2) -With sending IR, we can use the `send` method and optionally, +With sending IR, we can use the `send_once` method and optionally, send multiple by using the `repeat_count` keyword argument. Handling Errors @@ -126,7 +126,7 @@ Handling Errors client = lirc.Client() try: - client.send('some-remote', 'key_power') + client.send_once('some-remote', 'key_power') except lirc.LircdCommandFailureError as error: print('The command we sent failed! Check the error message') print(error) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 9302e08..6b65451 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -86,11 +86,11 @@ the ``lirc.Client``. import lirc client = lirc.Client() - client.send('our-remote-name', 'key-in-the-remote-file') + client.send_once('our-remote-name', 'key-in-the-remote-file') -Using the ``send()`` method is quite simple. For any method, such as this one, that +Using the ``send_once()`` method is quite simple. For any method, such as this one, that takes in a remote and a key, the parameters are always in that order with the remote -name first and then the key name. Because the ``send`` method does not get any meaningful +name first and then the key name. Because the ``send_once`` method does not get any meaningful data back from lircd, there is no return value from it. Instead, as is the case for most methods here that don't have a meaningful return value, a ``lirc.LircdCommandFailureError`` is raised if the command we sent failed. @@ -100,5 +100,5 @@ want to go to channel 33. .. code-block:: python - client.send('our-remote-name', 'key_3', repeat_count=2) + client.send_once('our-remote-name', 'key_3', repeat_count=2) diff --git a/lirc/client.py b/lirc/client.py index 0e3fa80..3365e30 100644 --- a/lirc/client.py +++ b/lirc/client.py @@ -64,7 +64,7 @@ class Client: """Close the connection to the socket.""" self.__connection.close() - def send(self, remote: str, key: str, repeat_count: int = 1) -> None: + def send_once(self, remote: str, key: str, repeat_count: int = 1) -> None: """ Send an lircd SEND_ONCE command. @@ -78,12 +78,12 @@ class Client: """ self.__send_command(f"SEND_ONCE {remote} {key} {repeat_count}") - def start_repeat(self, remote: str, key: str) -> None: + def send_start(self, remote: str, key: str) -> None: """ Send an lircd SEND_START command. This will repeat the given key until - stop_repeat() is called. + send_stop is called. Args: remote: The remote to use keys from. @@ -96,7 +96,7 @@ class Client: self.__last_send_start_key = key self.__send_command(f"SEND_START {remote} {key}") - def stop_repeat(self, remote: str = "", key: str = "") -> None: + def send_stop(self, remote: str = "", key: str = "") -> None: """ Send an lircd SEND_STOP command. diff --git a/tests/test_client.py b/tests/test_client.py index 4978c4d..f4edf10 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -47,15 +47,15 @@ def test_that_close_closes_the_socket(mock_client_and_connection): @pytest.mark.parametrize( "client_command, args, lircd_command", [ - ("send", {"remote": "REMOTE", "key": "KEY"}, "SEND_ONCE REMOTE KEY 1"), + ("send_once", {"remote": "REMOTE", "key": "KEY"}, "SEND_ONCE REMOTE KEY 1"), ( - "send", + "send_once", {"remote": "REMOTE", "key": "KEY", "repeat_count": 5}, "SEND_ONCE REMOTE KEY 5", ), - ("start_repeat", {"remote": "REMOTE", "key": "KEY"}, "SEND_START REMOTE KEY"), - ("stop_repeat", {}, "SEND_STOP "), - ("stop_repeat", {"remote": "REMOTE", "key": "KEY"}, "SEND_STOP REMOTE KEY"), + ("send_start", {"remote": "REMOTE", "key": "KEY"}, "SEND_START REMOTE KEY"), + ("send_stop", {}, "SEND_STOP "), + ("send_stop", {"remote": "REMOTE", "key": "KEY"}, "SEND_STOP REMOTE KEY"), ("list_remotes", {}, "LIST"), ("list_remote_keys", {"remote": "REMOTE"}, "LIST REMOTE"), ("start_logging", {"path": "PATH"}, "SET_INPUTLOG PATH"), @@ -80,9 +80,9 @@ def test_that_client_commands_send_the_correct_command( mock_client_and_connection, client_command, args, lircd_command ): """ - lirc.Client.send - lirc.Client.start_repeat - lirc.Client.stop_repeat + lirc.Client.send_once + lirc.Client.send_start + lirc.Client.send_stop lirc.Client.list_remotes lirc.Client.list_remote_keys lirc.Client.start_logging @@ -126,27 +126,27 @@ def test_unsuccessful_command_raises_custom_exception(mock_client_and_connection ) with pytest.raises(LircdCommandFailureError) as error: - client.send('remote', 'key') + client.send_once('remote', 'key') assert 'The `SEND_ONCE remote key 1` command sent to lircd failed: []' in str(error) -def test_last_start_repeat_remote_and_key_is_used(mock_client_and_connection): +def test_last_send_start_remote_and_key_is_used(mock_client_and_connection): """ - lirc.client.start_repeat - lirc.client.stop_repeat + lirc.client.send_start + lirc.client.send_stop - Ensure that when we call start_repeat, a subsequent call - to stop_repeat will use the remote and key start_repeat - had passed in as args if no args are provided to stop_repeat. + Ensure that when we call send_start, a subsequent call + to send_stop will use the remote and key send_start + had passed in as args if no args are provided to send_stop. """ client, connection = mock_client_and_connection connection._LircdConnection__socket.recv.return_value = ( b"BEGIN\nCOMMAND\nSUCCESS\nEND\n" ) - client.start_repeat('remote', 'key') + client.send_start('remote', 'key') - client.stop_repeat() # SUT + client.send_stop() # SUT connection._LircdConnection__socket.sendall.assert_called_with( "SEND_STOP remote key\n".encode("utf-8") |