|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from deebot_client.command import CommandResult, CommandWithMessageHandling |
| 8 | +from deebot_client.commands.xml import GetCleanSpeed, SetCleanSpeed |
| 9 | +from deebot_client.events import FanSpeedEvent, FanSpeedLevel |
| 10 | +from deebot_client.message import HandlingState |
| 11 | +from tests.commands import assert_command |
| 12 | + |
| 13 | +from . import get_request_xml |
| 14 | + |
| 15 | +if TYPE_CHECKING: |
| 16 | + from deebot_client.events.base import Event |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.parametrize( |
| 20 | + "speed", list(FanSpeedLevel) + [level.name for level in FanSpeedLevel] |
| 21 | +) |
| 22 | +def test_GetCleanSpeed_should_build_with_string_and_enums( |
| 23 | + speed: str | FanSpeedLevel, |
| 24 | +) -> None: |
| 25 | + """Test case for the way HA invokes the constructor.""" |
| 26 | + assert SetCleanSpeed(speed) is not None |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.parametrize( |
| 30 | + ("speed", "expected_event"), |
| 31 | + [ |
| 32 | + ("standard", FanSpeedEvent(FanSpeedLevel.NORMAL)), |
| 33 | + ("strong", FanSpeedEvent(FanSpeedLevel.MAX)), |
| 34 | + ], |
| 35 | + ids=["standard", "strong"], |
| 36 | +) |
| 37 | +async def test_get_fan_speed(speed: str, expected_event: Event) -> None: |
| 38 | + json = get_request_xml(f"<ctl ret='ok' speed='{speed}'/>") |
| 39 | + await assert_command(GetCleanSpeed(), json, expected_event) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.parametrize( |
| 43 | + ("xml", "expected_state"), |
| 44 | + [ |
| 45 | + ("<ctl ret='error'/>", HandlingState.ANALYSE_LOGGED), |
| 46 | + ("<ctl ret='ok' />", HandlingState.ANALYSE_LOGGED), |
| 47 | + ("<ctl ret='ok' speed='invalid'/>", HandlingState.ERROR), |
| 48 | + ], |
| 49 | + ids=["error", "no_state", "invalid_speed"], |
| 50 | +) |
| 51 | +async def test_get_fan_speed_error(xml: str, expected_state: HandlingState) -> None: |
| 52 | + json = get_request_xml(xml) |
| 53 | + await assert_command( |
| 54 | + GetCleanSpeed(), |
| 55 | + json, |
| 56 | + None, |
| 57 | + command_result=CommandResult(expected_state), |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +@pytest.mark.parametrize( |
| 62 | + ("command", "xml", "result"), |
| 63 | + [ |
| 64 | + ( |
| 65 | + SetCleanSpeed(FanSpeedLevel.MAX), |
| 66 | + "<ctl ret='ok' />", |
| 67 | + HandlingState.SUCCESS, |
| 68 | + ), |
| 69 | + ], |
| 70 | +) |
| 71 | +async def test_set_fan_speed( |
| 72 | + command: CommandWithMessageHandling, xml: str, result: HandlingState |
| 73 | +) -> None: |
| 74 | + json = get_request_xml(xml) |
| 75 | + await assert_command(command, json, None, command_result=CommandResult(result)) |
0 commit comments