Skip to content

Commit

Permalink
fix for applying retrieved service configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
bartvenmans committed Nov 13, 2024
1 parent cb075e2 commit df1a628
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tb_device_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(self, rate_limit, name=None, percentage=80):
self._minimal_limit = 1000000000
from_dict = isinstance(rate_limit, dict)
if from_dict:
self._rate_limit_dict = rate_limit.get('rateLimit', rate_limit)
self._rate_limit_dict = rate_limit.get('rateLimits', rate_limit)
name = rate_limit.get('name', name)
percentage = rate_limit.get('percentage', percentage)
self._no_limit = rate_limit.get('no_limit', False)
Expand Down Expand Up @@ -265,7 +265,7 @@ def set_limit(self, rate_limit, percentage=80):
@property
def __dict__(self):
return {
"rateLimit": self._rate_limit_dict,
"rateLimits": self._rate_limit_dict,
"name": self.name,
"percentage": self.percentage,
"no_limit": self._no_limit
Expand Down Expand Up @@ -694,12 +694,12 @@ def on_service_configuration(self, _, response, *args, **kwargs):
self.rate_limits_received = True
return
service_config = response
if not isinstance(service_config, dict) or 'rateLimit' not in service_config:
if not isinstance(service_config, dict) or 'rateLimits' not in service_config:
log.warning("Cannot retrieve service configuration, session will use default configuration.")
log.debug("Received the following response: %r", service_config)
return
if service_config.get("rateLimit"):
rate_limits_config = service_config.get("rateLimit")
if service_config.get("rateLimits"):
rate_limits_config = service_config.get("rateLimits")

if rate_limits_config.get('messages'):
self._messages_rate_limit.set_limit(rate_limits_config.get('messages'))
Expand Down

0 comments on commit df1a628

Please sign in to comment.