mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Small cleanups to the rate limit helper (#115621)
This commit is contained in:
parent
15ecd3ae31
commit
3963b3994b
@ -30,7 +30,7 @@ class KeyedRateLimit:
|
|||||||
@callback
|
@callback
|
||||||
def async_has_timer(self, key: Hashable) -> bool:
|
def async_has_timer(self, key: Hashable) -> bool:
|
||||||
"""Check if a rate limit timer is running."""
|
"""Check if a rate limit timer is running."""
|
||||||
return bool(self._rate_limit_timers and key in self._rate_limit_timers)
|
return key in self._rate_limit_timers
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_triggered(self, key: Hashable, now: float | None = None) -> None:
|
def async_triggered(self, key: Hashable, now: float | None = None) -> None:
|
||||||
@ -41,10 +41,8 @@ class KeyedRateLimit:
|
|||||||
@callback
|
@callback
|
||||||
def async_cancel_timer(self, key: Hashable) -> None:
|
def async_cancel_timer(self, key: Hashable) -> None:
|
||||||
"""Cancel a rate limit time that will call the action."""
|
"""Cancel a rate limit time that will call the action."""
|
||||||
if not self._rate_limit_timers or key not in self._rate_limit_timers:
|
if handle := self._rate_limit_timers.pop(key, None):
|
||||||
return
|
handle.cancel()
|
||||||
|
|
||||||
self._rate_limit_timers.pop(key).cancel()
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_remove(self) -> None:
|
def async_remove(self) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user