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

Fixed loading mqtt handlers #1531

Merged
Merged
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
18 changes: 10 additions & 8 deletions thingsboard_gateway/connectors/mqtt/mqtt_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ def load_handlers(self, handler_flavor, mandatory_keys, accepted_handlers_list):
handler_configuration = self.config.get(handler_flavor)
if handler_configuration is None:
request_mapping_config = self.config.get("requestsMapping", {})
if isinstance(request_mapping_config, list):
handler_configuration = []
if isinstance(request_mapping_config, dict):
handler_configuration = None
for request_mapping in request_mapping_config:
if request_mapping.get("requestType") == handler_flavor:
handler_configuration.append(request_mapping.get("requestValue"))
if request_mapping == handler_flavor:
handler_configuration = request_mapping_config[request_mapping]

if not handler_configuration:
self.__log.debug("'%s' section missing from configuration", handler_flavor)
Expand Down Expand Up @@ -583,20 +583,22 @@ def _parse_device_info(device_info, topic, content):
device_name_match = search(device_info["deviceNameExpression"], topic)
if device_name_match is not None:
found_device_name = device_name_match.group(0)
elif device_info.get('deviceNameExpressionSource') == 'message' or device_info.get(
'deviceNameExpression') == 'constant':
elif device_info.get('deviceNameExpressionSource') == 'message':
found_device_name = TBUtility.get_value(device_info["deviceNameExpression"], content,
expression_instead_none=True)
elif device_info.get('deviceNameExpressionSource') == 'constant':
found_device_name = device_info["deviceNameExpression"]

# Get device type (if any), either from topic or from content
if device_info.get("deviceProfileExpressionSource") == 'topic':
device_type_match = search(device_info["deviceProfileExpression"], topic)
found_device_type = device_type_match.group(0) if device_type_match is not None else device_info[
"deviceProfileExpression"]
elif device_info.get("deviceProfileExpressionSource") == 'message' or device_info.get(
'deviceNameExpression') == 'constant':
elif device_info.get("deviceProfileExpressionSource") == 'message':
found_device_type = TBUtility.get_value(device_info["deviceProfileExpression"], content,
expression_instead_none=True)
elif device_info.get("deviceProfileExpressionSource") == 'constant':
found_device_type = TBUtility.get_value(device_info["deviceProfileExpression"], content,)

return found_device_name, found_device_type

Expand Down
Loading