esphome-docs icon indicating copy to clipboard operation
esphome-docs copied to clipboard

fan: fix on_direction_set docs example to use FanDirection enum

Open leodrivera opened this issue 3 months ago โ€ข 3 comments

Description:

Fix incorrect example in the fan.on_direction_set trigger. The docs compared the direction parameter to an integer (x == 0), which is invalid because x is an enum (FanDirection). Also ensure the YAML args value is a quoted string.

Updated example:

fan:
  - platform: speed # or any other platform
    # ...
    on_direction_set:
    - logger.log:
        format: "Fan Direction was changed to %s!"
        args: [ 'x == FanDirection::FORWARD ? "FORWARD" : "REVERSE"' ]

This resolves compilation issues and aligns with the enum usage shown elsewhere in the page.

Related issue (if applicable): fixes esphome/esphome-docs#5248

Pull request in esphome with YAML changes (if applicable):

  • N/A

Checklist:

  • [ ] I am merging into next because this is new documentation that has a matching pull-request in esphome as linked above.
    or

  • [x] I am merging into current because this is a fix, change and/or adjustment in the current documentation and is not for a new component or feature.

  • [ ] Link added in /components/index.rst when creating new documents for new components or cookbook.

References:

leodrivera avatar Sep 17 '25 21:09 leodrivera

Deploy Preview for esphome ready!

Name Link
Latest commit ef26417f41e320b5414055727dffde69fa726b10
Latest deploy log https://app.netlify.com/projects/esphome/deploys/69339495a32cbc0008003260
Deploy Preview https://deploy-preview-5377--esphome.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Sep 17 '25 21:09 netlify[bot]

Walkthrough

Updated the fan.on_direction_set documentation to state the x parameter is of type FanDirection, changed the example to compare against FanDirection::FORWARD, and wrapped the ternary expression in quotes so the args entry is valid YAML.

Changes

Cohort / File(s) Summary
Docs: Fan trigger parameter and example fix
content/components/fan/_index.md
Specify that x is FanDirection; replace numeric comparison (x == 0) with enum comparison (x == FanDirection::FORWARD); wrap the ternary expression in single quotes so args is valid YAML.

Estimated code review effort

๐ŸŽฏ 1 (Trivial) | โฑ๏ธ ~3 minutes

Pre-merge checks and finishing touches

โœ… Passed checks (5 passed)
Check name Status Explanation
Title check โœ… Passed The title clearly and accurately describes the main change: fixing the on_direction_set documentation example to use the FanDirection enum instead of integer comparisons.
Description check โœ… Passed The description is directly related to the changeset, explaining the incorrect example, the problem with type mismatch, and providing the corrected YAML with enum comparison.
Linked Issues check โœ… Passed The pull request fully addresses all requirements from issue #5248: corrects the enum type comparison (FanDirection::FORWARD instead of integer 0), ensures proper YAML string quoting, and resolves compilation errors.
Out of Scope Changes check โœ… Passed All changes are scoped to fixing the on_direction_set trigger documentation example as specified in the linked issue, with no extraneous modifications.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
โœจ Finishing touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

๐Ÿ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 22f1e99135636da7602563d7be5a205f2dfb3ede and ef26417f41e320b5414055727dffde69fa726b10.

๐Ÿ“’ Files selected for processing (1)
  • content/components/fan/_index.md (2 hunks)
๐Ÿงฐ Additional context used
๐Ÿ““ Path-based instructions (1)
**

โš™๏ธ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • content/components/fan/_index.md
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
๐Ÿ”‡ Additional comments (1)
content/components/fan/_index.md (1)

242-242: Documentation fix correctly addresses enum type and YAML formatting issues.

The changes properly:

  1. Specify that x is of type FanDirection (line 242), eliminating ambiguity
  2. Update the example to compare against FanDirection::FORWARD instead of an integer (line 251), resolving the type mismatch that caused compilation errors
  3. Quote the ternary expression as a YAML string literal to avoid parsing issues (line 251)

This aligns the trigger documentation with the enum usage shown elsewhere in the file (e.g., line 347) and fixes the compilation error referenced in issue #5248.

Also applies to: 251-251


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Sep 17 '25 21:09 coderabbitai[bot]

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions.

github-actions[bot] avatar Dec 06 '25 02:12 github-actions[bot]