def closest_event(self, dt: datetime.datetime) -> tuple[str, float]:
        """Get the closest sunset or sunrise event."""
        (prev_event, prev_ts), (next_event, next_ts) = self.prev_and_next_events(dt)
        if SUN_EVENT_SUNRISE in (prev_event, next_event):
            ts_event = prev_ts if prev_event == SUN_EVENT_SUNRISE else next_ts
            return SUN_EVENT_SUNRISE, ts_event
        if SUN_EVENT_SUNSET in (prev_event, next_event):
            ts_event = prev_ts if prev_event == SUN_EVENT_SUNSET else next_ts
            return SUN_EVENT_SUNSET, ts_event
        msg = "No sunrise or sunset event found."
        raise ValueError(msg)
Get the closest sunset or sunrise event.
custom_components/adaptive_lighting/color_and_brightness.py