Home Assistant Unofficial Reference 2024.12.1
homeassistant.helpers.ratelimit.KeyedRateLimit Class Reference

Public Member Functions

None __init__ (self, HomeAssistant hass)
 
None async_cancel_timer (self, Hashable key)
 
bool async_has_timer (self, Hashable key)
 
None async_remove (self)
 
None async_triggered (self, Hashable key, float|None now=None)
 

Public Attributes

 hass
 

Private Member Functions

float|None _Ts (self, Hashable key, float|None rate_limit, float now, Callable[[*_Ts], None] action, **_Ts args)
 

Detailed Description

Class to track rate limits.

Definition at line 15 of file ratelimit.py.

Constructor & Destructor Documentation

◆ __init__()

None homeassistant.helpers.ratelimit.KeyedRateLimit.__init__ (   self,
HomeAssistant  hass 
)
Initialize ratelimit tracker.

Definition at line 18 of file ratelimit.py.

Member Function Documentation

◆ _Ts()

float | None homeassistant.helpers.ratelimit.KeyedRateLimit._Ts (   self,
Hashable  key,
float | None  rate_limit,
float  now,
Callable[[*_Ts], None]  action,
**_Ts  args 
)
private
Check rate limits and schedule an action if we hit the limit.

If the rate limit is hit:
    Schedules the action for when the rate limit expires
    if there are no pending timers. The action must
    be called in async.

    Returns the time the rate limit will expire

If the rate limit is not hit:

    Return None

Definition at line 52 of file ratelimit.py.

◆ async_cancel_timer()

None homeassistant.helpers.ratelimit.KeyedRateLimit.async_cancel_timer (   self,
Hashable  key 
)
Cancel a rate limit time that will call the action.

Definition at line 39 of file ratelimit.py.

◆ async_has_timer()

bool homeassistant.helpers.ratelimit.KeyedRateLimit.async_has_timer (   self,
Hashable  key 
)
Check if a rate limit timer is running.

Definition at line 28 of file ratelimit.py.

◆ async_remove()

None homeassistant.helpers.ratelimit.KeyedRateLimit.async_remove (   self)
Remove all timers.

Definition at line 45 of file ratelimit.py.

◆ async_triggered()

None homeassistant.helpers.ratelimit.KeyedRateLimit.async_triggered (   self,
Hashable  key,
float | None   now = None 
)
Call when the action we are tracking was triggered.

Definition at line 33 of file ratelimit.py.

Member Data Documentation

◆ hass

homeassistant.helpers.ratelimit.KeyedRateLimit.hass

Definition at line 23 of file ratelimit.py.


The documentation for this class was generated from the following file: