# Path: thingsboard_gateway/connectors/ble/ble_uplink_converter.py
# class BLEUplinkConverter(Converter):
#     def convert(self, config, data):


from pprint import pformat
from re import findall
from thingsboard_gateway.connectors.ble.ble_uplink_converter import BLEUplinkConverter, log

        try:
            self.dict_result["telemetry"] = []
            self.dict_result["attributes"] = []

            for section in ('telemetry', 'attributes'):
                for item in data[section]:
                    try:
                        expression_arr = findall(r'\[[^\s][0-9:]*]', item['valueExpression'])
                        converted_data = item['valueExpression']

                        for exp in expression_arr:
                            indexes = exp[1:-1].split(':')

                            data_to_replace = ''
                            if len(indexes) == 2:
                                from_index, to_index = indexes
                                concat_arr = item['data'][
                                             int(from_index) if from_index != '' else None:int(
                                                 to_index) if to_index != '' else None]
                                for sub_item in concat_arr:
                                    data_to_replace += str(sub_item)
                            else:
                                data_to_replace += str(item['data'][int(indexes[0])])

                            converted_data = converted_data.replace(exp, data_to_replace)

                        if item.get('key') is not None:
                            self.dict_result[section].append({item['key']: converted_data})
                        else:

# Path: thingsboard_gateway/connectors/ble/ble_uplink_converter.py
# class BLEUplinkConverter(Converter):
#     def convert(self, config, data):


# Path: thingsboard_gateway/connectors/ble/bytes_ble_uplink_converter.py
from pprint import pformat
from re import findall
from thingsboard_gateway.connectors.ble.ble_uplink_converter import BLEUplinkConverter, log


        try:
            self.dict_result["telemetry"] = []
            self.dict_result["attributes"] = []

            for section in ('telemetry', 'attributes'):
                for item in data[section]:
                    try:
                        expression_arr = findall(r'\[[^\s][0-9:]*]', item['valueExpression'])
                        converted_data = item['valueExpression']

                        for exp in expression_arr:
                            indexes = exp[1:-1].split(':')

                            data_to_replace = ''
                            if len(indexes) == 2:
                                from_index, to_index = indexes
                                concat_arr = item['data'][
                                             int(from_index) if from_index != '' else None:int(
                                                 to_index) if to_index != '' else None]
                                for sub_item in concat_arr:
                                    data_to_replace += str(sub_item)
                            else:
                                data_to_replace += str(item['data'][int(indexes[0])])

                            converted_data = converted_data.replace(exp, data_to_replace)

                        if item.get('key') is not None:
                            self.dict_result[section].append({item['key']: converted_data})
                        else:

                            log.error('Key for %s not found in config: %s', config['type'], config[section])