diff --git a/deebot_client/commands/fan_speed.py b/deebot_client/commands/fan_speed.py index 822f6aa9..26e129e8 100644 --- a/deebot_client/commands/fan_speed.py +++ b/deebot_client/commands/fan_speed.py @@ -2,22 +2,11 @@ from collections.abc import Mapping from typing import Any -from ..events import FanSpeedEvent +from ..events import FanSpeedEvent, FanSpeedLevel from ..message import HandlingResult, MessageBodyDataDict -from ..util import DisplayNameIntEnum from .common import EventBus, NoArgsCommand, SetCommand -class FanSpeedLevel(DisplayNameIntEnum): - """Enum class for all possible fan speed levels.""" - - # Values should be sort from low to high on their meanings - QUIET = 1000 - NORMAL = 0 - MAX = 1 - MAX_PLUS = 2, "max+" - - class GetFanSpeed(NoArgsCommand, MessageBodyDataDict): """Get fan speed command.""" @@ -31,7 +20,7 @@ def _handle_body_data_dict( :return: A message response """ - event_bus.notify(FanSpeedEvent(FanSpeedLevel(int(data["speed"])).display_name)) + event_bus.notify(FanSpeedEvent(FanSpeedLevel(int(data["speed"])))) return HandlingResult.success() diff --git a/deebot_client/events/__init__.py b/deebot_client/events/__init__.py index d883573f..e72365b0 100644 --- a/deebot_client/events/__init__.py +++ b/deebot_client/events/__init__.py @@ -7,6 +7,7 @@ from ..events.base import Event from ..models import Room, VacuumState from ..util import DisplayNameIntEnum +from .fan_speed import FanSpeedEvent, FanSpeedLevel from .map import ( MajorMapEvent, MapSetEvent, @@ -81,13 +82,6 @@ class ErrorEvent(Event): description: str | None -@dataclass(frozen=True) -class FanSpeedEvent(Event): - """Fan speed event representation.""" - - speed: str - - @unique class LifeSpan(str, Enum): """Enum class for all possible life span components.""" diff --git a/deebot_client/events/fan_speed.py b/deebot_client/events/fan_speed.py new file mode 100644 index 00000000..c361f7b3 --- /dev/null +++ b/deebot_client/events/fan_speed.py @@ -0,0 +1,24 @@ +"""Fan speed event module.""" + + +from dataclasses import dataclass + +from ..util import DisplayNameIntEnum +from .base import Event + + +class FanSpeedLevel(DisplayNameIntEnum): + """Enum class for all possible fan speed levels.""" + + # Values should be sort from low to high on their meanings + QUIET = 1000 + NORMAL = 0 + MAX = 1 + MAX_PLUS = 2 + + +@dataclass(frozen=True) +class FanSpeedEvent(Event): + """Fan speed event representation.""" + + speed: FanSpeedLevel diff --git a/tests/commands/test_fan_speed.py b/tests/commands/test_fan_speed.py index dcbfcc83..2d15e12f 100644 --- a/tests/commands/test_fan_speed.py +++ b/tests/commands/test_fan_speed.py @@ -12,11 +12,12 @@ def test_FanSpeedLevel_unique() -> None: async def test_GetFanSpeed() -> None: json = get_request_json({"speed": 2}) - await assert_command(GetFanSpeed(), json, FanSpeedEvent("max+")) + await assert_command(GetFanSpeed(), json, FanSpeedEvent(FanSpeedLevel.MAX_PLUS)) @pytest.mark.parametrize( - "value, expected", [("quiet", 1000), ("max+", 2), (0, 0), (FanSpeedLevel.MAX, 1)] + "value, expected", + [("quiet", 1000), ("max_plus", 2), (0, 0), (FanSpeedLevel.MAX, 1)], ) def test_SetFanSpeed(value: str | int | FanSpeedLevel, expected: int) -> None: command = SetFanSpeed(value)