Skip to content

Commit

Permalink
Fix linter errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvn23 committed Sep 17, 2024
1 parent 1512048 commit 1cf2795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 11 additions & 6 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.")
Expand Down
9 changes: 6 additions & 3 deletions tests/test_commandprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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...",
),
]

Expand Down

0 comments on commit 1cf2795

Please sign in to comment.