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 issue 1316 and 1326 #1327

Merged
merged 3 commits into from
Apr 10, 2024
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
22 changes: 13 additions & 9 deletions thingsboard_gateway/tb_utility/tb_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from logging import getLogger
from re import search, findall
from uuid import uuid4
from distutils.util import strtobool

from cryptography import x509
from cryptography.x509.oid import NameOID
Expand Down Expand Up @@ -127,7 +128,7 @@ def get_value(expression, body=None, value_type="string", get_tag=False, express

@staticmethod
def get_values(expression, body=None, value_type="string", get_tag=False, expression_instead_none=False):
expression_arr = findall(r'\$\{[${A-Za-z0-9. ^\]\[*_:]*\}', expression)
expression_arr = findall(r'\$\{[${A-Za-z0-9. ^\]\[*_:"]*\}', expression)

values = [TBUtility.get_value(exp, body, value_type=value_type, get_tag=get_tag,
expression_instead_none=expression_instead_none) for exp in expression_arr]
Expand Down Expand Up @@ -244,13 +245,16 @@ def convert_data_type(data, new_type, use_eval=False):
return data

evaluated_data = eval(data, globals(), {}) if use_eval else data
if 'int' in new_type or 'long' in new_type:
return int(float(evaluated_data))
elif 'float' == new_type or 'double' == new_type:
return float(evaluated_data)
elif 'bool' in new_type:
return bool(evaluated_data)
else:
try:
if 'int' in new_type or 'long' in new_type:
return int(float(evaluated_data))
elif 'float' == new_type or 'double' == new_type:
return float(evaluated_data)
elif 'bool' in new_type:
return bool(strtobool(evaluated_data))
else:
return str(evaluated_data)
except ValueError:
return str(evaluated_data)

@staticmethod
Expand All @@ -264,4 +268,4 @@ def get_or_create_connector_id(connector_conf):
end_find = connector_conf.find("{id_var_end}")
if start_find > -1 and end_find > -1:
connector_id = connector_conf[start_find + 13:end_find]
return connector_id
return connector_id
Loading