diff options
-rw-r--r-- | glucometerutils/drivers/fsprecisionneo.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/glucometerutils/drivers/fsprecisionneo.py b/glucometerutils/drivers/fsprecisionneo.py index 504dad7..89c80d9 100644 --- a/glucometerutils/drivers/fsprecisionneo.py +++ b/glucometerutils/drivers/fsprecisionneo.py @@ -32,16 +32,21 @@ from glucometerutils.support import freestyle # The type is a string because it precedes the parsing of the object. _TYPE_GLUCOSE_READING = '7' +_TYPE_KETONE_READING = '9' _NeoReading = collections.namedtuple('_NeoReading', ( - 'type', # 7 = blood glucose + 'type', # 7 = blood glucose, 9 = blood ketone 'id', 'month', 'day', 'year', # year is two-digits 'hour', 'minute', 'unknown2', 'value', - 'unknown3', 'unknown4', 'unknown5', 'unknown6', 'unknown7', - 'unknown8', 'unknown9', 'unknown10', 'unknown11', 'unknown12', + # Extra trailing and so-far-unused fields; so discard them: + # * for blood glucose: 10 unknown trailing fields + #'unknown3', 'unknown4', 'unknown5', 'unknown6', 'unknown7', + #'unknown8', 'unknown9', 'unknown10', 'unknown11', 'unknown12', + # * for blood ketone: 2 unknown trailing fields + #'unknown3', 'unknown4', )) @@ -66,15 +71,21 @@ class Device(freestyle.FreeStyleHidDevice): def get_readings(self): """Iterate through the reading records in the device.""" for record in self._get_multirecord(b'$result?'): - if not record or record[0] != _TYPE_GLUCOSE_READING: + cls = None + if record and record[0] == _TYPE_GLUCOSE_READING: + cls = common.GlucoseReading + elif with_ketone and record or record[0] == _TYPE_KETONE_READING: + cls = common.KetoneReading + else: continue - # Build a _reading object by parsing each of the entries in the CSV - # as integers. - raw_reading = _NeoReading._make([int(v) for v in record]) + # Build a _reading object by parsing each of the entries in the raw + # record + values = [int(v) for v in record] + raw_reading = _NeoReading._make(values[:len(_NeoReading._fields]) timestamp = datetime.datetime( raw_reading.year + 2000, raw_reading.month, raw_reading.day, raw_reading.hour, raw_reading.minute) - yield common.GlucoseReading(timestamp, raw_reading.value) + yield cls(timestamp, raw_reading.value) |