From e5e3c4c4b59b9997d4f5eefbda0f6cdb89ef4ae4 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Fri, 24 Jul 2020 14:25:51 -0500 Subject: 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. --- lirc/lirc.py | 13 ++++++++++--- 1 file 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( -- cgit v1.2.3