Skip to content

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

Open
kylev wants to merge 5 commits into
sblibs:mainfrom
kylev:kv_abstract_vert
Open

fix: allow API users to think about vertical oscillation "angle" in degrees.#533
kylev wants to merge 5 commits into
sblibs:mainfrom
kylev:kv_abstract_vert

Conversation

@kylev

@kylev kylev commented Jun 26, 2026

Copy link
Copy Markdown

A little tickery provides enough abstraction that API users can think in degrees or with byte-value awareness. This makes integrating with common input controls more natural.

A little tickery provides enough abstraction that API users can think in degrees or with byte-value awareness. This makes integrating with common input controls more natural.
Copilot AI review requested due to automatic review settings June 26, 2026 19:28
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
switchbot/const/fan.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make the Standing Fan vertical oscillation API more intuitive by allowing callers to specify 90° (degrees) while still emitting the correct device byte encoding (0x5F / 95) for the command payload.

Changes:

  • Added a regression test ensuring set_vertical_oscillation_angle(90) produces the same command as byte value 95.
  • Modified VerticalOscillationAngle to introduce a degree-aware “90” entry while still mapping it to the device byte value used on the wire.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/test_fan.py Adds coverage for passing 90 as an int and asserting correct byte encoding in the emitted command.
switchbot/const/fan.py Adjusts the vertical oscillation angle enum to support degree-based inputs for 90°.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread switchbot/const/fan.py Outdated
@kylev kylev changed the title Allow API users to think in degrees. fix: Allow API users to think about vertical oscillation in degrees. Jun 26, 2026
@kylev kylev changed the title fix: Allow API users to think about vertical oscillation in degrees. fix: allow API users to think about vertical oscillation "angle" in degrees. Jun 26, 2026
@kylev kylev force-pushed the kv_abstract_vert branch from 7ade4db to 7b499e9 Compare June 26, 2026 20:18
Comment thread switchbot/const/fan.py
Comment on lines +63 to +68

@classmethod
def _missing_(cls, value: int) -> VerticalOscillationAngle | None:
if value == 90:
return cls.ANGLE_90
return None

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants