Skip to content

Commit

Permalink
- Add support for configuring throttling for polling in order to prev…
Browse files Browse the repository at this point in the history
…ent CLF overheating & RF performance degradation
  • Loading branch information
kormax committed Nov 18, 2024
1 parent 1458704 commit d28ea10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def configure_homekey_service(config: dict, nfc_device, repository=None):
express=config.get("express", True),
finish=config.get("finish"),
flow=config.get("flow"),
# Poll no more than ~6 times a second by default
throttle_polling=float(config.get("throttle_polling") or 0.15),
)
return service

Expand Down
5 changes: 5 additions & 0 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ def __init__(
express: bool = True,
finish: str = "silver",
flow: str = "fast",
throttle_polling = 0.1
) -> None:
self.repository = repository
self.clf = clf
self.throttle_polling = throttle_polling
self.express = express in (True, "True", "true", "1")

try:
Expand Down Expand Up @@ -115,7 +117,10 @@ def _read_homekey(self):
flag_2=self.express,
).pack(),
)

if remote_target is None:
# Throttle polling attempts to prevent overheating & RF performance degradation
time.sleep(max(0, self.throttle_polling - time.monotonic() + start))
return

target = activate(self.clf, remote_target)
Expand Down

0 comments on commit d28ea10

Please sign in to comment.