<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def step(self):
 """Apply the current stage of the transition based on current time."""

        if self.cancelled or self.finished:
            return

        if not self.pwm_stages:
            self._finish()
            return

        if self.duration == 0:
            progress = 1
        else:
            run_time = time.time() - self._start_time
            progress = max(0, min(1, run_time / self.duration))
        self.stage_index = math.ceil((len(self.pwm_stages) - 1) * progress)
        stage = self.pwm_stages[self.stage_index]
        self._driver.set_pwm(stage)

        if progress == 1:
            self._finish()