mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
Fix docstring for expect_response and rename the associated exception
This commit is contained in:
@@ -217,7 +217,7 @@ class ChameleonCLI:
|
||||
continue
|
||||
# start process cmd
|
||||
unit.on_exec(args_parse_result)
|
||||
except (chameleon_cmd.NegativeResponseError, chameleon_cli_unit.ArgsParserError) as e:
|
||||
except (chameleon_cmd.UnexpectedResponseError, chameleon_cli_unit.ArgsParserError) as e:
|
||||
print(f"{colorama.Fore.RED}{str(e)}{colorama.Style.RESET_ALL}")
|
||||
except Exception:
|
||||
print(f"CLI exception: {colorama.Fore.RED}{traceback.format_exc()}{colorama.Style.RESET_ALL}")
|
||||
|
||||
@@ -2,7 +2,7 @@ import enum
|
||||
|
||||
import chameleon_com
|
||||
import chameleon_status
|
||||
from chameleon_utils import NegativeResponseError, expect_response
|
||||
from chameleon_utils import UnexpectedResponseError, expect_response
|
||||
|
||||
DATA_CMD_GET_APP_VERSION = 1000
|
||||
DATA_CMD_CHANGE_MODE = 1001
|
||||
|
||||
@@ -4,12 +4,16 @@ from typing import Union
|
||||
import chameleon_status
|
||||
|
||||
|
||||
class NegativeResponseError(Exception):
|
||||
class UnexpectedResponseError(Exception):
|
||||
"""
|
||||
Not positive response
|
||||
Unexpected response exception
|
||||
"""
|
||||
|
||||
def expect_response(accepted_responses):
|
||||
def expect_response(accepted_responses: Union[int, list[int]]):
|
||||
"""
|
||||
Decorator for wrapping a Chameleon CMD function to check its response
|
||||
for expected return codes and throwing an exception otherwise
|
||||
"""
|
||||
if isinstance(accepted_responses, int):
|
||||
accepted_responses = [accepted_responses]
|
||||
|
||||
@@ -20,9 +24,9 @@ def expect_response(accepted_responses):
|
||||
|
||||
if ret.status not in accepted_responses:
|
||||
if ret.status in chameleon_status.Device and ret.status in chameleon_status.message:
|
||||
raise NegativeResponseError(chameleon_status.message[ret.status])
|
||||
raise UnexpectedResponseError(chameleon_status.message[ret.status])
|
||||
else:
|
||||
raise NegativeResponseError(f"Not positive response and unknown status {ret.status}")
|
||||
raise UnexpectedResponseError(f"Unexpected response and unknown status {ret.status}")
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
Reference in New Issue
Block a user