ekmmeters.py
def convertData(self, contents, def_buf, kwh_scale=ScaleKWH.EmptyScale):
        """ Move data from raw tuple into scaled and conveted values.

        Args:
            contents (tuple): Breakout of passed block from unpackStruct().
            def_buf (): Read buffer destination.
            kwh_scale (int):  :class:`~ekmmeters.ScaleKWH` as int, from Field.kWhScale`

        Returns:
            bool: True on completion.
        """
        log_str = ""
        count = 0
        
        # getting scale does not require a full read.  It does require that the
        # reads have the scale value in the first block read.  This requirement
        # is filled by default in V3 and V4 requests
        if kwh_scale == ScaleKWH.EmptyScale:
            scale_offset = int(def_buf.keys().index(Field.kWh_Scale))
            self.m_kwh_precision = kwh_scale = int(contents[scale_offset])

        for fld in def_buf:

            if def_buf[fld][MeterData.CalculatedFlag]:
                count += 1
                continue

            if len(contents) == 0:
                count += 1
                continue

            try:  # scrub up messes on a field by field basis
                raw_data = contents[count]
                fld_type = def_buf[fld][MeterData.TypeValue]
                fld_scale = def_buf[fld][MeterData.ScaleValue]

                if fld_type == FieldType.Float:
                    float_data = float(str(raw_data))
                    divisor = 1
                    if fld_scale == ScaleType.KWH:
                        divisor = 1
                        if kwh_scale == ScaleKWH.Scale10:
                            divisor = 10
                        elif kwh_scale == ScaleKWH.Scale100:
                            divisor = 100
                        elif (kwh_scale != ScaleKWH.NoScale) and (kwh_scale != ScaleKWH.EmptyScale):
                            ekm_log("Unrecognized kwh scale.")
                    elif fld_scale == ScaleType.Div10:
                        divisor = 10
                    elif fld_scale == ScaleType.Div100:
                        divisor = 100
                    elif fld_scale != ScaleType.No:
                        ekm_log("Unrecognized float scale.")
                    float_data /= divisor
                    float_data_str = str(float_data)
                    def_buf[fld][MeterData.StringValue] = float_data_str
                    def_buf[fld][MeterData.NativeValue] = float_data

                elif fld_type == FieldType.Hex:
                    hex_data = raw_data.encode('hex')
                    def_buf[fld][MeterData.StringValue] = hex_data
                    def_buf[fld][MeterData.NativeValue] = hex_data

                elif fld_type == FieldType.Int:
                    integer_data = int(raw_data)
                    integer_data_str = str(integer_data)
                    if len(integer_data_str) == 0:
                        integer_data_str = str(0)
                    def_buf[fld][MeterData.StringValue] = integer_data_str
                    def_buf[fld][MeterData.NativeValue] = integer_data

                elif fld_type == FieldType.String:
                    string_data = str(raw_data)
                    def_buf[fld][MeterData.StringValue] = string_data
                    def_buf[fld][MeterData.NativeValue] = string_data

                elif fld_type == FieldType.PowerFactor:
                    def_buf[fld][MeterData.StringValue] = str(raw_data)
                    def_buf[fld][MeterData.NativeValue] = str(raw_data)

                else:
                    ekm_log("Unrecognized field type")

                log_str = log_str + '"' + fld + '":  "' + def_buf[fld][MeterData.StringValue] + '"\n'

            except:
                ekm_log("Exception on Field:" + str(fld))
                ekm_log(traceback.format_exc(sys.exc_info()))
                self.writeCmdMsg("Exception on Field:" + str(fld))

            count += 1

        return True
def convertData(self, contents, def_buf, kwh_scale=ScaleKWH.EmptyScale):
        """ Move data from raw tuple into scaled and conveted values.

        Args:
            contents (tuple): Breakout of passed block from unpackStruct().
            def_buf (): Read buffer destination.
            kwh_scale (int):  :class:`~ekmmeters.ScaleKWH` as int, from Field.kWhScale`

        Returns:
            bool: True on completion.
        """
        log_str = ""
        count = 0
        
        # getting scale does not require a full read.  It does require that the
        # reads have the scale value in the first block read.  This requirement
        # is filled by default in V3 and V4 requests
        if kwh_scale == ScaleKWH.EmptyScale:
            scale_offset = int(def_buf.keys().index(Field.kWh_Scale))
            self.m_kwh_precision = kwh_scale = int(contents[scale_offset])

        for fld in def_buf:

            if def_buf[fld][MeterData.CalculatedFlag]:
                count += 1
                continue

            if len(contents) == 0:
                count += 1
                continue

            try:  # scrub up messes on a field by field basis
                raw_data = contents[count]
                fld_type = def_buf[fld][MeterData.TypeValue]
                fld_scale = def_buf[fld][MeterData.ScaleValue]

                if fld_type == FieldType.Float:
                    float_data = float(str(raw_data))
                    divisor = 1
                    if fld_scale == ScaleType.KWH:
                        divisor = 1
                        if kwh_scale == ScaleKWH.Scale10:
                            divisor = 10
                        elif kwh_scale == ScaleKWH.Scale100:
                            divisor = 100
                        elif (kwh_scale != ScaleKWH.NoScale) and (kwh_scale != ScaleKWH.EmptyScale):
                            ekm_log("Unrecognized kwh scale.")
                    elif fld_scale == ScaleType.Div10:
                        divisor = 10
                    elif fld_scale == ScaleType.Div100:
                        divisor = 100
                    elif fld_scale != ScaleType.No:
                        ekm_log("Unrecognized float scale.")
                    float_data /= divisor
                    float_data_str = str(float_data)
                    def_buf[fld][MeterData.StringValue] = float_data_str
                    def_buf[fld][MeterData.NativeValue] = float_data

                elif fld_type == FieldType.Hex:
                    hex_data = raw_data.encode('hex')
                    def_buf[fld][MeterData.StringValue] = hex_data
                    def_buf[fld][MeterData.NativeValue] = hex_data

                elif fld_type == FieldType.Int:
                    integer_data = int(raw_data)
                    integer_data_str = str(integer_data)
                    if len(integer_data_str) == 0:
                        integer_data_str = str(0)
                    def_buf[fld][MeterData.StringValue] = integer_data_str
                    def_buf[fld][MeterData.NativeValue] = integer_data

                elif fld_type == FieldType.String:
                    string_data = str(raw_data)
                    def_buf[fld][MeterData.StringValue] = string_data
                    def_buf[fld][MeterData.NativeValue] = string_data

                elif fld_type == FieldType.PowerFactor:
                    def_buf[fld][MeterData.StringValue] = str(raw_data)
                    def_buf[fld][MeterData.NativeValue] = str(raw_data)

                else:
                    ekm_log("Unrecognized field type")

                log_str = log_str + '"' + fld + '":  "' + def_buf[fld][MeterData.StringValue] + '"\n'

            except:
                ekm_log("Exception on Field:" + str(fld))
                ekm_log(traceback.format_exc(sys.exc_info()))
                self.writeCmdMsg("Exception on Field:" + str(fld))

            count += 1

        return True
Move data from raw tuple into scaled and conveted values.

        Args:
            contents (tuple): Breakout of passed block from unpackStruct().
            def_buf (): Read buffer destination.
            kwh_scale (int):  :class:`~ekmmeters.ScaleKWH` as int, from Field.kWhScale`

        Returns:
            bool: True on completion.