def _is_state_event(event: Event, from_or_to_state: Iterable[str]):
    """Match state event when either 'from_state' or 'to_state' matches."""
    return (
        (old_state := event.data.get("old_state")) is not None
        and old_state.state in from_or_to_state
    ) or (
        (new_state := event.data.get("new_state")) is not None
        and new_state.state in from_or_to_state
    )
Match state event when either 'from_state' or 'to_state' matches.
custom_components/adaptive_lighting/switch.py