summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-07-24 14:25:51 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-07-24 14:25:51 -0500
commite5e3c4c4b59b9997d4f5eefbda0f6cdb89ef4ae4 (patch)
tree4b6f2bae52ce15660784d755a775ffaaf51b9a95
parentFix package imports and add command failure error (diff)
downloadlirc-e5e3c4c4b59b9997d4f5eefbda0f6cdb89ef4ae4.zip
Raise command failure error if not a success
This makes more sense than a success attribute on the response object since we can separate the algorithm from the error handling code, which is more typical in python.
-rw-r--r--lirc/lirc.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/lirc/lirc.py b/lirc/lirc.py
index 373d06a..0380872 100644
--- a/lirc/lirc.py
+++ b/lirc/lirc.py
@@ -6,10 +6,11 @@ from typing import List, Union
from lirc.exceptions import (
InvalidReplyPacketFormatError,
+ LircCommandFailureError,
LircSocketError,
LircSocketTimeoutError,
)
-from lirc.response import LircResponse
+from lirc.lirc_response import LircResponse
DEFAULT_ADDRESS_LINUX = "/var/run/lirc/lircd"
DEFAULT_ADDRESS_WINDOWS = ("localhost", 8765)
@@ -149,10 +150,13 @@ class Lirc:
:param packet: The reply packet from lirc.
:return: a response object containing information on the command sent.
+ :raises LircCommandFailureError: If the command we send to LIRC fails.
+ The data from the response of the command, likey the error message,
+ is used as the message.
"""
lines = packet.split("\n")
current_index = 0
- response = LircResponse("", False, [])
+ response = LircResponse("", [])
if lines[current_index] == "BEGIN":
current_index += 1
@@ -162,7 +166,7 @@ class Lirc:
response.command = lines[current_index]
current_index += 1
- response.success = True if lines[current_index] == "SUCCESS" else False
+ command_success = True if lines[current_index] == "SUCCESS" else False
current_index += 1
if lines[current_index] == "END":
@@ -179,6 +183,9 @@ class Lirc:
for line in islice(lines, current_index, current_index + data_length):
response.data.append(line)
+ if not command_success:
+ raise LircCommandFailureError(response.data)
+
return response
def send_once(