summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Martin <s.martin49@gmail.com>2017-09-23 18:44:25 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-09-25 16:12:06 +0200
commit8790a18d254e33ae222c3894f45cb1639a620fd5 (patch)
treea25d6f024c9863f30fb6db62678d6737399736db
parentfslibre: add ketone reading support (diff)
downloadglucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar.gz
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar.bz2
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar.lz
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar.xz
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.tar.zst
glucometerutils-8790a18d254e33ae222c3894f45cb1639a620fd5.zip
-rw-r--r--glucometerutils/drivers/fsprecisionneo.py27
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)