fix: allow API users to think about vertical oscillation "angle" in degrees.#533
Open
kylev wants to merge 5 commits into
Open
fix: allow API users to think about vertical oscillation "angle" in degrees.#533kylev wants to merge 5 commits into
kylev wants to merge 5 commits into
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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 value95. - Modified
VerticalOscillationAngleto 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.
21 tasks
kylev
commented
Jun 27, 2026
Comment on lines
+63
to
+68
|
|
||
| @classmethod | ||
| def _missing_(cls, value: int) -> VerticalOscillationAngle | None: | ||
| if value == 90: | ||
| return cls.ANGLE_90 | ||
| return None |
Author
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.