diff --git a/tests/helpers.py b/tests/helpers.py index 03853ef..e4e04b3 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -32,13 +32,23 @@ async def _wait(): def respond_to_reports( - cmds: list[OpenThermReport] = [], responses: list[str] = [] + cmds: list[OpenThermReport] | None = None, responses: list[str] | None = None ) -> Callable[[OpenThermCommand, str, float | None], str]: """ Respond to PR= commands with test values. Override response values by specifying cmds and responses in order. """ + if len(cmds) != len(responses): + raise ValueError( + "There should be an equal amount of provided cmds and responses" + ) + + if cmds is None: + cmds = [] + if responses is None: + responses = [] + default_responses = { OpenThermReport.ABOUT: "A=OpenTherm Gateway 5.8", OpenThermReport.BUILD: "B=17:52 12-03-2023", @@ -58,11 +68,6 @@ def respond_to_reports( OpenThermReport.DHW: "W=1", } - if len(cmds) != len(responses): - raise ValueError( - "There should be an equal amount of provided cmds and responses" - ) - for cmd, response in zip(cmds, responses): if cmd not in default_responses: raise ValueError(f"Command {cmd} not found in default responses.") diff --git a/tests/test_commandprocessor.py b/tests/test_commandprocessor.py index b946faa..553dbe0 100644 --- a/tests/test_commandprocessor.py +++ b/tests/test_commandprocessor.py @@ -149,7 +149,8 @@ async def test_issue_cmd(caplog, pygw_proto): ( "pyotgw.commandprocessor", logging.WARNING, - f"Command {OpenThermCommand.CONTROL_SETPOINT_2} failed with InvalidCommand, retrying...", + f"Command {OpenThermCommand.CONTROL_SETPOINT_2} failed with InvalidCommand," + " retrying...", ), ] caplog.clear() @@ -185,12 +186,14 @@ async def test_issue_cmd(caplog, pygw_proto): ( "pyotgw.commandprocessor", logging.WARNING, - f"Command {OpenThermCommand.CONTROL_HEATING_2} failed with Error 03, retrying...", + f"Command {OpenThermCommand.CONTROL_HEATING_2} failed with Error 03," + " retrying...", ), ( "pyotgw.commandprocessor", logging.WARNING, - f"Command {OpenThermCommand.CONTROL_HEATING_2} failed with {OpenThermCommand.CONTROL_HEATING_2}: BV, retrying...", + f"Command {OpenThermCommand.CONTROL_HEATING_2} failed with" + f" {OpenThermCommand.CONTROL_HEATING_2}: BV, retrying...", ), ]