def sun_position(self, dt: datetime.datetime) -> float:
        """Calculate the position of the sun, between [-1, 1]."""
        target_ts = dt.timestamp()
        (_, prev_ts), (next_event, next_ts) = self.prev_and_next_events(dt)
        h, x = (
            (prev_ts, next_ts)
            if next_event in (SUN_EVENT_SUNSET, SUN_EVENT_SUNRISE)
            else (next_ts, prev_ts)
        )
        # k = -1 between sunset and sunrise (sun below horizon)
        # k = 1 between sunrise and sunset (sun above horizon)
        k = 1 if next_event in (SUN_EVENT_SUNSET, SUN_EVENT_NOON) else -1
        return k * (1 - ((target_ts - h) / (h - x)) ** 2)
Calculate the position of the sun, between [-1, 1].
webapp/color_and_brightness.py