Stumbling fan if playing video on Plex in a converted quality (Software PWM issue)

Disclaimer: This demonstrates only a temporary workaround, waiting for hardware PWM on Pi5 gets ready

The issue is that on expected fanless operation, the fan stumbles and spins slowly when Plex plays a reduced quality video that requires conversion.
You might have noticed as well that sometimes suddenly the fan starts spinnig for a fraction of a second without any reason.

I found a way to workaround it by forcing the software PWM to 0 for the case of zero duty.
For that I modified the tr function in fan.py as

    def tr(self):
        while True:
           if self.value[1] > self.period_s * .9:
                self.line.set_value(0)
                time.sleep(0.1)
           else:
                self.line.set_value(1)
                time.sleep(self.value[0])
                self.line.set_value(0)
                time.sleep(self.value[1])

To proove the solution you could use self.period_s * 1.1 instead of self.period_s * .9 meaning that the fixing if clause will never be executed and the function behaves as in origin.

Regards
Michael

Everything you do - you do so at your own risk