Skip to content

Commit

Permalink
change speed type of FanSpeedEvent (#281)
Browse files Browse the repository at this point in the history
* change speed type of FanSpeedEvent

* adjust fan speed tests
  • Loading branch information
edenhaus authored Jul 29, 2023
1 parent 03bfac5 commit 0034c52
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
15 changes: 2 additions & 13 deletions deebot_client/commands/fan_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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()


Expand Down
8 changes: 1 addition & 7 deletions deebot_client/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand Down
24 changes: 24 additions & 0 deletions deebot_client/events/fan_speed.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions tests/commands/test_fan_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0034c52

Please sign in to comment.