Skip to content

homematicip.connection.buckets

Buckets

Class to manage the rate limiting of the HomematicIP Cloud API. The implementation is based on the token bucket algorithm.

__init__

__init__

Initialize the Buckets with a token bucket algorithm.

Parameters:

Name Type Description Default

tokens

int

The number of tokens in the bucket.

required

fill_rate

int

The fill rate of the bucket in tokens every x seconds.

required

take async

take

Get a single token from the bucket. Return True if successful, False otherwise.

Parameters:

Name Type Description Default

tokens

int

The number of tokens to take from the bucket. Default is 1.

1

Returns:

Type Description
bool

True if successful, False otherwise.

tokens async

tokens

Get the number of tokens in the bucket. Refill the bucket if necessary.

wait_and_take async

wait_and_take

Wait until a token is available and then take it. Return True if successful, False otherwise.

Parameters:

Name Type Description Default

timeout

int

The maximum time to wait for a token in seconds. Default is 120 seconds.

120

tokens

int

The number of tokens to take from the bucket. Default is 1.

1

Returns:

Type Description
bool

True if successful, False otherwise.