Skip to content

Switchbot Cloud: Fixed Circulator Fan on start error#165241

Draft
XiaoLing-git wants to merge 6 commits intohome-assistant:devfrom
XiaoLing-git:fixed_circulator_fan_issue_0310
Draft

Switchbot Cloud: Fixed Circulator Fan on start error#165241
XiaoLing-git wants to merge 6 commits intohome-assistant:devfrom
XiaoLing-git:fixed_circulator_fan_issue_0310

Conversation

@XiaoLing-git
Copy link
Contributor

@XiaoLing-git XiaoLing-git commented Mar 10, 2026

Proposed change

  1. fixed issue :Circulator Fan has not sensor for battery level

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @SeraphicRav, @laurence-presland, @Gigatrappeur, mind taking a look at this pull request as it has been labeled with an integration (switchbot_cloud) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of switchbot_cloud can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign switchbot_cloud Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Contributor

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

Fixes a SwitchBot Cloud startup crash caused by treating the Circulator Fan device type as a sensor-capable device, which led to a KeyError during sensor platform setup.

Changes:

  • Adjust device classification so Circulator Fan is only set up as a fan (not as a sensor device).
  • Add/update test fixtures and fan tests to include both Battery Circulator Fan and Circulator Fan device types.

Reviewed changes

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

File Description
homeassistant/components/switchbot_cloud/__init__.py Stops adding Circulator Fan devices to the sensor setup list to avoid sensor-platform KeyError.
tests/components/switchbot_cloud/__init__.py Introduces a separate fixture for Battery Circulator Fan vs Circulator Fan.
tests/components/switchbot_cloud/test_fan.py Expands fan tests to cover both circulator fan device types.

Copilot AI review requested due to automatic review settings March 10, 2026 03:12
Copy link
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Copilot AI review requested due to automatic review settings March 10, 2026 10:27
Copy link
Contributor

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

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

Comment on lines +79 to 80
entity_id = "fan.fan_1"
state = hass.states.get(entity_id)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The fan controller tests now exercise only the non-battery Circulator Fan path, and the Battery Circulator Fan command flow is no longer covered (beyond the coordinator-None case). Since this PR also changes fan command behavior, please add equivalent service-call tests for BATTERY_CIRCULATOR_FAN_INFO (and ideally assert the expected send_command arguments/sequence) to prevent regressions for the battery model.

Copilot uses AI. Check for mistakes.
await self.send_api_command(
command=BatteryCirculatorFanCommands.SET_WIND_MODE,
parameters=str(BatteryCirculatorFanMode.DIRECT.value),
)
await self.send_api_command(
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being removed? (I'm not saying it shouldn't, but I would like to know the reasoning.)

Copy link
Member

Choose a reason for hiding this comment

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

Can we parameterize the tests such that the battery powered fan is also tested?

version="V1.0",
deviceId="battery-fan-id-1",
deviceName="battery-fan-1",
deviceType="Battery Circulator Fan",
hubDeviceId="test-hub-id",
)

CIRCULATOR_FAN_INFO = Device(
version="V1.0",
deviceId="battery-fan-id-1",
Copy link
Member

Choose a reason for hiding this comment

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

the device id is the same as the battery-powerd fan

Suggested change
deviceId="battery-fan-id-1",
deviceId="fan-id-1",

@home-assistant home-assistant bot marked this pull request as draft March 11, 2026 16:45
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants