-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from flaviut/backoff-roborock
roborock: fallback & longer map name fetch backoff
- Loading branch information
Showing
2 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
custom_components/xiaomi_cloud_map_extractor/common/backoff.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import random | ||
|
||
|
||
class Backoff: | ||
"""Exponential backoff with jitter.""" | ||
|
||
def __init__(self, min_sleep, max_sleep): | ||
self.min_sleep = min_sleep | ||
self.sleep = min_sleep | ||
self.max_sleep = max_sleep | ||
|
||
def backoff(self): | ||
self.sleep = min(self.max_sleep, random.uniform(self.min_sleep, self.sleep * 3)) | ||
return self.sleep |