Skip to content

Add SwitchBot Standing Fan (FAN2) support#459

Open
fankai777 wants to merge 5 commits intosblibs:masterfrom
fankai777:feat/standing-fan
Open

Add SwitchBot Standing Fan (FAN2) support#459
fankai777 wants to merge 5 commits intosblibs:masterfrom
fankai777:feat/standing-fan

Conversation

@fankai777
Copy link
Contributor

Summary

Add full BLE control support for the SwitchBot Standing Fan (model FAN2), extending the existing Circulator Fan implementation.

Changes

Features

  • SwitchbotStandingFan inherits from SwitchbotFan, reusing on/off, speed, and oscillation controls.
  • Added 5 preset modes: normal, natural, sleep, baby, custom_natural (via StandingFanMode enum).
  • Added set_horizontal_oscillation_angle() / set_vertical_oscillation_angle() for angle selection (30°/60°/90°).
  • Added set_night_light() control with 3 states: off, level_1, level_2.

Parser

  • adv_parser.py: Registered Standing Fan BLE advertisement IDs (\x00\x11\x07\x60, \x01\x11\x07\x60).
  • SwitchbotStandingFan.get_basic_info(): Parses battery, on/off, horizontal/vertical oscillation, mode (1-5), speed, firmware from BLE response.

Tests

  • Added 28 unit tests covering all Standing Fan functionality:
    • 5 preset modes (including custom_natural)
    • get_basic_info parsing with oscillation bits and mode=5
    • Horizontal/vertical oscillation angle commands (30/60/90)
    • Night light control (off/level_1/level_2)
    • Independent horizontal/vertical oscillation toggle

fankai777 and others added 4 commits March 6, 2026 17:47
- Add SwitchbotStandingFan device class with 5 preset modes
- Support independent horizontal/vertical oscillation control with angle selection
- Add night light control (off/level_1/level_2)
- Register Standing Fan BLE advertisement IDs
- Add unit tests for fan instantiation and on/off

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Test all 5 preset modes including custom_natural
- Test get_basic_info parsing with mode=5 (custom_natural) and oscillation bits
- Test horizontal/vertical oscillation angle setting (30/60/90)
- Test night light control (off/level_1/level_2)
- Test independent horizontal/vertical oscillation commands

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
switchbot/__init__.py 100.00% <100.00%> (ø)
switchbot/adv_parser.py 97.81% <ø> (ø)
switchbot/const/__init__.py 100.00% <100.00%> (ø)
switchbot/const/fan.py 100.00% <100.00%> (ø)
switchbot/devices/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.

Cover the False branches of set_horizontal_oscillation and
set_vertical_oscillation, and add tests for the state getter methods.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds BLE support for the SwitchBot Standing Fan (FAN2) by extending the existing fan device implementation and wiring the new model into advertisement parsing and public exports.

Changes:

  • Introduces SwitchbotStandingFan with standing-fan-specific preset modes plus controls for oscillation angles and night light.
  • Extends fan basic-info parsing to expose horizontal/vertical oscillation flags.
  • Registers Standing Fan model identifiers in the BLE advertisement parser and adds unit tests for the new functionality.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
switchbot/devices/fan.py Adds standing fan device class + new oscillation primitives and updates basic-info parsing.
switchbot/const/fan.py Adds StandingFanMode enum.
switchbot/const/__init__.py Exposes StandingFanMode and adds STANDING_FAN to SwitchbotModel.
switchbot/adv_parser.py Registers Standing Fan advertisement IDs to be parsed as a fan device.
switchbot/__init__.py Exports StandingFanMode and SwitchbotStandingFan at the package level.
tests/test_fan.py Adds unit tests covering standing fan behaviors and command formatting.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +19 to +24
COMMAND_START_OSCILLATION = f"{COMMAND_HEAD}02010101" # H+V start
COMMAND_STOP_OSCILLATION = f"{COMMAND_HEAD}02010202" # H+V stop
COMMAND_START_HORIZONTAL_OSCILLATION = f"{COMMAND_HEAD}020101ff" # H start, V keep
COMMAND_STOP_HORIZONTAL_OSCILLATION = f"{COMMAND_HEAD}020102ff" # H stop, V keep
COMMAND_START_VERTICAL_OSCILLATION = f"{COMMAND_HEAD}0201ff01" # H keep, V start
COMMAND_STOP_VERTICAL_OSCILLATION = f"{COMMAND_HEAD}0201ff02" # H keep, V stop
Comment on lines 90 to 95
@update_after_operation
async def set_oscillation(self, oscillating: bool) -> bool:
"""Send command to set fan oscillation"""
if oscillating:
return await self._send_command(COMMAND_START_OSCILLATION)
return await self._send_command(COMMAND_STOP_OSCILLATION)
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