ソースを参照

fix: allow API users to think about vertical oscillation "angle" in degrees. (#533)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Kyle VanderBeek 2 日 前
コミット
fdd8b1cddd
2 ファイル変更16 行追加0 行削除
  1. 6 0
      switchbot/const/fan.py
  2. 10 0
      tests/test_fan.py

+ 6 - 0
switchbot/const/fan.py

@@ -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

+ 10 - 0
tests/test_fan.py

@@ -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):