(self)
If active, compute the brightness for the red color,
        depending on the time that has passed since starting the sound.
If active, compute the brightness for the red color,
        depending on the time that has passed since starting the sound.
If active compute the brightness for the red color depending on the time that has passed since starting the sound .
def compute(self) -> None:
        """If active, compute the brightness for the red color,
        depending on the time that has passed since starting the sound."""
        # do not compute if the alarm is not active
        if self.consumers == 0:
            return
        self.time_passed += self.manager.seconds_per_frame
        if self.time_passed >= self.sound_repetition:
            self.sound_count += 1
            self.time_passed %= self.sound_repetition

        if self.sound_count >= 4:
            self.factor = 0
            return
        if self.time_passed < self.increasing_duration:
            self.factor = self.time_passed / self.increasing_duration
        elif self.time_passed < self.sound_duration - self.decreasing_duration:
            self.factor = 1
        elif self.time_passed < self.sound_duration:
            self.factor = (
                1
                - (self.time_passed - (self.sound_duration - self.decreasing_duration))
                / self.decreasing_duration
            )
        else:
            self.factor = 0

        # Ideally, the pwr led would flash with increasing frequency,
        # but the Pi can not handle enough script executions to make it look good.
        if self.pwr_led_enabled and self.factor < 0.7:
            leds.disable_pwr_led()
            self.pwr_led_enabled = False
        elif not self.pwr_led_enabled and self.factor >= 0.7:
            leds.enable_pwr_led()
            self.pwr_led_enabled = True
def compute ( self ) -> None : # do not compute if the alarm is not active if self . consumers == 0 : return self . time_passed += self . manager . seconds_per_frame if self . time_passed >= self . sound_repetition : self . sound_count += 1 self . time_passed %= self . sound_repetition if self . sound_count >= 4 : self . factor = 0 return if self . time_passed < self . increasing_duration : self . factor = self . time_passed / self . increasing_duration elif self . time_passed < self . sound_duration - self . decreasing_duration : self . factor = 1 elif self . time_passed < self . sound_duration : self . factor = ( 1 - ( self . time_passed - ( self . sound_duration - self . decreasing_duration ) ) / self . decreasing_duration ) else : self . factor = 0 # Ideally, the pwr led would flash with increasing frequency, # but the Pi can not handle enough script executions to make it look good. if self . pwr_led_enabled and self . factor < 0.7 : leds . disable_pwr_led ( ) self . pwr_led_enabled = False elif not self . pwr_led_enabled and self . factor >= 0.7 : leds . enable_pwr_led ( ) self . pwr_led_enabled = True