Skip to content

Commit

Permalink
Merge pull request #1 from zwoabier/zwoabier-fix-1316-1326
Browse files Browse the repository at this point in the history
Fix regex and data conversion to bool
  • Loading branch information
zwoabier authored Mar 4, 2024
2 parents ef9bbb3 + 6c69592 commit da1b3a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 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 @@ -249,7 +250,7 @@ def convert_data_type(data, new_type, use_eval=False):
elif 'float' == new_type or 'double' == new_type:
return float(evaluated_data)
elif 'bool' in new_type:
return bool(evaluated_data)
return bool(strtobool(evaluated_data))
else:
return str(evaluated_data)

Expand All @@ -264,4 +265,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

0 comments on commit da1b3a0

Please sign in to comment.