fan: fix on_direction_set docs example to use FanDirection enum
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
nextbecause this is new documentation that has a matching pull-request in esphome as linked above.
or -
[x] I am merging into
currentbecause 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.rstwhen creating new documents for new components or cookbook.
References:
- Issue report: fan.on_direction_set Trigger Example Uses Incorrect Type Comparison
- Docs section being fixed:
fan.on_direction_setTrigger
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
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 fixcontent/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:
- Specify that
xis of typeFanDirection(line 242), eliminating ambiguity- Update the example to compare against
FanDirection::FORWARDinstead of an integer (line 251), resolving the type mismatch that caused compilation errors- 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
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.