Repository navigation
Simplify trigger expr - #932
Merged
craigbarratt merged 3 commits intoNov 27, 2026
Merged
Conversation
…in trigger expressions) custom-components#921 was squashed into 8b3fde3. This reverts its second commit, a2e13b7 ("let multi-line trigger expressions span lines without brackets"), and the docs follow-up 933e177, and keeps its first commit, 1e39bf5 ("let trigger expressions start and end with blanks"). The implicit brackets read a multi-line trigger expression differently from Python: a missing operator at a line break is joined with the next line instead of being a SyntaxError. As in Python, a multi-line trigger expression needs brackets of its own again. Adapted to custom-components#927: strip_trigger_expr() now lives in decorators/base.py, since decorators/state.py imports from it, and the first commit's tests lose their legacy decorator variants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests kept from the first commit of custom-components#921 also checked str.strip(), CPython's own errors and AstEval.parse(), which this change doesn't touch, and repeated the same code path for several decorators. What stays checks what the change adds: blanks around an expression or a state name are ignored in each kind of decorator, and a trailing # comment doesn't swallow the next @state_trigger entry. strip_trigger_expr() no longer checks for non-strings: the arguments it gets are already validated as strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a "Multi-line trigger expressions" section with the ways to write a long trigger expression: brackets in a triple-quoted string, adjacent strings, and named parts joined with an f-string. The note in @state_trigger now points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
craigbarratt
approved these changes
Nov 27, 2026
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.
Follow-up to #921, as agreed there: keep stripping the blanks around a trigger expression, drop the implicit brackets around multi-line expressions, and document that a multi-line expression goes in brackets, as in Python.
Commits
It's easiest to review them one by one.
Revert the second commit of Let trigger expressions start and end with blanks and span lines (#617) #921. Let trigger expressions start and end with blanks and span lines (#617) #921 was squashed, so a plain
git revertisn't possible: this applies the second commit, a2e13b7, and the docs follow-up 933e177 in reverse, resolving the parts that Remove legacy decorators #927 changed since. The code ends up as in the first commit, 1e39bf5, adapted to Remove legacy decorators #927:strip_trigger_expr()moves todecorators/base.py, sincedecorators/state.pyimports from it;eval.pyis back to its state before Let trigger expressions start and end with blanks and span lines (#617) #921.Drop trigger expression tests that only check Python. Some kept tests checked
str.strip(), CPython's own errors andAstEval.parse(), or repeated the same code path. The tests that remain cover:# commentin one of several@state_triggerentries.strip_trigger_expr()loses itsisinstancecheck: its arguments are already validated as strings.Document multi-line trigger expressions. A new section in the
@state_triggerdocs shows three ways to write a long expression:Behavior compared with master
SyntaxErroragain, as in Python. Is it possible to use multiline strings in state trigger decorators? #617's example needs(after the opening"""and)before the closing one.# commentno longer swallows the next@state_triggerentry.@state_triggerentries are still joined withany([...]), as before Let trigger expressions start and end with blanks and span lines (#617) #921.