Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for applying retrieved service configuration #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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