Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions switchbot/const/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ class VerticalOscillationAngle(Enum):
ANGLE_30 = 30
ANGLE_60 = 60
ANGLE_90 = 95

@classmethod
def _missing_(cls, value: int) -> VerticalOscillationAngle | None:
if value == 90:
return cls.ANGLE_90
return None
Comment on lines +63 to +68

@kylev kylev Jun 27, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also happy to rewrite this with a less "mysterious" approach:

Suggested change
@classmethod
def _missing_(cls, value: int) -> VerticalOscillationAngle | None:
if value == 90:
return cls.ANGLE_90
return None
@classmethod
def from_degrees(cls, value: int) -> VerticalOscillationAngle:
try:
return cls[f"ANGLE_{value}"]
except KeyError:
raise ValueError(f"{value} degrees has no corresponding {cls.__name__}") from None

10 changes: 10 additions & 0 deletions tests/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@ async def test_standing_fan_set_vertical_oscillation_angle_int(byte_value):
assert cmd == f"{fan.COMMAND_SET_OSCILLATION_PARAMS}FFFF{byte_value:02X}FF"


@pytest.mark.asyncio
async def test_standing_fan_set_vertical_oscillation_angle_90():
"""Raw-int callers may also use 90 degrees, which maps to byte 0x5F (95)."""
standing_fan = create_standing_fan_for_testing()
await standing_fan.set_vertical_oscillation_angle(90)
cmd = standing_fan._send_command.call_args[0][0]
byte_value = VerticalOscillationAngle.ANGLE_90.value
assert cmd == f"{fan.COMMAND_SET_OSCILLATION_PARAMS}FFFF{byte_value:02X}FF"


@pytest.mark.asyncio
@pytest.mark.parametrize("angle", [0, 45, 120, -1])
async def test_standing_fan_set_vertical_oscillation_angle_invalid(angle):
Expand Down
Loading