@@ -337,18 +337,18 @@ def __init__(self, hass: HomeAssistant, config: TriggerConfig) -> None:
337337 self ._options = config .options or {}
338338 self ._target = config .target
339339
340- def is_from_state (self , from_state : State , to_state : State ) -> bool :
341- """Check if the state matches the origin state ."""
342- return not self .is_to_state (from_state )
340+ def is_valid_transition (self , from_state : State , to_state : State ) -> bool :
341+ """Check if the origin state is not an expected target states ."""
342+ return not self .is_valid_state (from_state )
343343
344344 @abc .abstractmethod
345- def is_to_state (self , state : State ) -> bool :
346- """Check if the state matches the target state."""
345+ def is_valid_state (self , state : State ) -> bool :
346+ """Check if the new state matches the expected state(s) ."""
347347
348348 def check_all_match (self , entity_ids : set [str ]) -> bool :
349349 """Check if all entity states match."""
350350 return all (
351- self .is_to_state (state )
351+ self .is_valid_state (state )
352352 for entity_id in entity_ids
353353 if (state := self ._hass .states .get (entity_id )) is not None
354354 )
@@ -357,7 +357,7 @@ def check_one_match(self, entity_ids: set[str]) -> bool:
357357 """Check that only one entity state matches."""
358358 return (
359359 sum (
360- self .is_to_state (state )
360+ self .is_valid_state (state )
361361 for entity_id in entity_ids
362362 if (state := self ._hass .states .get (entity_id )) is not None
363363 )
@@ -394,12 +394,12 @@ def state_change_listener(
394394 if not from_state or from_state .state in (STATE_UNAVAILABLE , STATE_UNKNOWN ):
395395 return
396396
397- # The trigger should never fire if the previous state was not the from state
398- if not to_state or not self .is_from_state ( from_state , to_state ):
397+ # The trigger should never fire if the new state is not valid
398+ if not to_state or not self .is_valid_state ( to_state ):
399399 return
400400
401- # The trigger should never fire if the new state is not the to state
402- if not self .is_to_state ( to_state ):
401+ # The trigger should never fire if the transition is not valid
402+ if not self .is_valid_transition ( from_state , to_state ):
403403 return
404404
405405 if behavior == BEHAVIOR_LAST :
@@ -433,8 +433,8 @@ class EntityStateTriggerBase(EntityTriggerBase):
433433
434434 _to_state : str
435435
436- def is_to_state (self , state : State ) -> bool :
437- """Check if the state matches the target state."""
436+ def is_valid_state (self , state : State ) -> bool :
437+ """Check if the new state matches the expected state."""
438438 return state .state == self ._to_state
439439
440440
@@ -444,12 +444,12 @@ class ConditionalEntityStateTriggerBase(EntityTriggerBase):
444444 _from_states : set [str ]
445445 _to_states : set [str ]
446446
447- def is_from_state (self , from_state : State , to_state : State ) -> bool :
448- """Check if the state matches the origin state ."""
447+ def is_valid_transition (self , from_state : State , to_state : State ) -> bool :
448+ """Check if the origin state matches the expected ones ."""
449449 return from_state .state in self ._from_states
450450
451- def is_to_state (self , state : State ) -> bool :
452- """Check if the state matches the target state ."""
451+ def is_valid_state (self , state : State ) -> bool :
452+ """Check if the new state matches the expected states ."""
453453 return state .state in self ._to_states
454454
455455
@@ -459,8 +459,8 @@ class EntityStateAttributeTriggerBase(EntityTriggerBase):
459459 _attribute : str
460460 _attribute_to_state : str
461461
462- def is_to_state (self , state : State ) -> bool :
463- """Check if the state matches the target state ."""
462+ def is_valid_state (self , state : State ) -> bool :
463+ """Check if the new state attribute matches the expected one ."""
464464 return state .attributes .get (self ._attribute ) == self ._attribute_to_state
465465
466466
0 commit comments