MaxWinterstein / toogoodtogo-ha-mqtt-bridge

36 stars 8 forks source link

Simplify randomize_time by random of 0 to 20 seconds #114

Closed MaxWinterstein closed 1 year ago

MaxWinterstein commented 1 year ago

@Dielee while checking the other PR I came across mentioned function, and how it created trouble. When having long sleep times, like e.g. mentioned here the 'take half of the sleep and randomize with it' creates really really long sleep times.

Sadly I cannot remember the intention behind it. If I assume correctly, it was just to stress the API less and prevent calls from everyone at the same second (e.g. 17:00:00)?

I simplified it by just adding a random of 0-20 seconds and added some test cases, that prove the expected next fetch interval is in the range it should be.

Might have a look if my sleepy brain was on a correct path?

Dielee commented 1 year ago

Nice, this should work 👍