summaryrefslogtreecommitdiffstats
path: root/glucometerutils/drivers/fsoptium.py
diff options
context:
space:
mode:
Diffstat (limited to 'glucometerutils/drivers/fsoptium.py')
-rw-r--r--glucometerutils/drivers/fsoptium.py101
1 files changed, 52 insertions, 49 deletions
diff --git a/glucometerutils/drivers/fsoptium.py b/glucometerutils/drivers/fsoptium.py
index 395494c..618fffa 100644
--- a/glucometerutils/drivers/fsoptium.py
+++ b/glucometerutils/drivers/fsoptium.py
@@ -29,8 +29,8 @@ from glucometerutils.support import serial
_CLOCK_RE = re.compile(
- r'^Clock:\t(?P<month>[A-Z][a-z]{2}) (?P<day>[0-9]{2}) (?P<year>[0-9]{4})\t'
- r'(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2})$')
+ r'^Clock:\t(?P<month>[A-Z][a-z]{2}) (?P<day>[0-9]{2}) (?P<year>[0-9]{4})\t'
+ r'(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2})$')
# The reading can be HI (padded to three-characters by a space) if the value was
# over what the meter was supposed to read. Unlike the "Clock:" line, the months
@@ -38,29 +38,33 @@ _CLOCK_RE = re.compile(
# characters, so accept a space or 'e'/'y' at the end of the month name. Also,
# the time does *not* include seconds.
_READING_RE = re.compile(
- r'^(?P<reading>HI |[0-9]{3}) (?P<month>[A-Z][a-z]{2})[ ey] (?P<day>[0-9]{2}) '
- r'(?P<year>[0-9]{4}) (?P<time>[0-9]{2}:[0-9]{2}) (?P<type>[GK]) 0x00$')
+ r'^(?P<reading>HI |[0-9]{3}) '
+ r'(?P<month>[A-Z][a-z]{2})[ ey] '
+ r'(?P<day>[0-9]{2}) '
+ r'(?P<year>[0-9]{4}) '
+ r'(?P<time>[0-9]{2}:[0-9]{2}) '
+ r'(?P<type>[GK]) 0x00$')
_CHECKSUM_RE = re.compile(
- r'^(?P<checksum>0x[0-9A-F]{4}) END$')
+ r'^(?P<checksum>0x[0-9A-F]{4}) END$')
# There are two date format used by the device. One uses three-letters month
# names, and that's easy enough. The other uses three-letters month names,
# except for (at least) July. So ignore the fourth character.
# explicit mapping. Note that the mapping *requires* a trailing whitespace.
_MONTH_MATCHES = {
- 'Jan': 1,
- 'Feb': 2,
- 'Mar': 3,
- 'Apr': 4,
- 'May': 5,
- 'Jun': 6,
- 'Jul': 7,
- 'Aug': 8,
- 'Sep': 9,
- 'Oct': 10,
- 'Nov': 11,
- 'Dec': 12
+ 'Jan': 1,
+ 'Feb': 2,
+ 'Mar': 3,
+ 'Apr': 4,
+ 'May': 5,
+ 'Jun': 6,
+ 'Jul': 7,
+ 'Aug': 8,
+ 'Sep': 9,
+ 'Oct': 10,
+ 'Nov': 11,
+ 'Dec': 12
}
@@ -99,8 +103,8 @@ class Device(serial.SerialDevice):
logging.debug('Received response: %r', response)
- # We always want to decode the output, and remove stray \r\n. Any failure in
- # decoding means the output is invalid anyway.
+ # We always want to decode the output, and remove stray \r\n. Any
+ # failure in decoding means the output is invalid anyway.
decoded_response = [line.decode('ascii').rstrip('\r\n')
for line in response]
return decoded_response
@@ -109,7 +113,7 @@ class Device(serial.SerialDevice):
self._send_command('xmem') # ignore output this time
self._fetch_device_information()
- def disconnect(self):
+ def disconnect(self): # pylint: disable=no-self-use
return
def _fetch_device_information(self):
@@ -126,13 +130,13 @@ class Device(serial.SerialDevice):
self.device_glucose_unit_ = common.Unit.MMOL_L
else: # I only have a mmol/l device, so I can't be sure.
self.device_glucose_unit_ = common.Unit.MG_DL
- # There are more entries: Clock, Market, ROM and Usage, but we don't care
- # for those here.
+ # There are more entries: Clock, Market, ROM and Usage, but we don't
+ # care for those here.
elif parsed_line[0] == 'CMD OK':
return
- # I have not figured out why this happens, but sometimes it's echoing back
- # the commands and not replying to them.
+ # I have not figured out why this happens, but sometimes it's echoing
+ # back the commands and not replying to them.
raise exceptions.ConnectionFailed()
def get_meter_info(self):
@@ -142,11 +146,11 @@ class Device(serial.SerialDevice):
A common.MeterInfo object.
"""
return common.MeterInfo(
- 'Freestyle Optium glucometer',
- serial_number=self.get_serial_number(),
- version_info=(
- 'Software version: ' + self.get_version(),),
- native_unit=self.get_glucose_unit())
+ 'Freestyle Optium glucometer',
+ serial_number=self.get_serial_number(),
+ version_info=(
+ 'Software version: ' + self.get_version(),),
+ native_unit=self.get_glucose_unit())
def get_version(self):
"""Returns an identifier of the firmware version of the glucometer.
@@ -208,11 +212,6 @@ class Device(serial.SerialDevice):
return self.get_datetime()
def zero_log(self):
- """Zeros out the data log of the device.
-
- This function will clear the memory of the device deleting all the readings
- in an irrecoverable way.
- """
raise NotImplementedError
def get_readings(self):
@@ -221,19 +220,20 @@ class Device(serial.SerialDevice):
Args:
unit: The glucose unit to use for the output.
- Yields:
- A tuple (date, value) of the readings in the glucometer. The value is a
- floating point in the unit specified; if no unit is specified, the default
- unit in the glucometer will be used.
+ Yields: A tuple (date, value) of the readings in the glucometer. The
+ value is a floating point in the unit specified; if no unit is
+ specified, the default unit in the glucometer will be used.
Raises:
- exceptions.InvalidResponse: if the response does not match what expected.
+ exceptions.InvalidResponse: if the response does not match what '
+ expected.
+
"""
data = self._send_command('xmem')
- # The first line is empty, the second is the serial number, the third the
- # version, the fourth the current time, and the fifth the record count.. The
- # last line has a checksum and the end.
+ # The first line is empty, the second is the serial number, the third
+ # the version, the fourth the current time, and the fifth the record
+ # count.. The last line has a checksum and the end.
count = int(data[4])
if count != (len(data) - 6):
raise exceptions.InvalidResponse('\n'.join(data))
@@ -244,12 +244,14 @@ class Device(serial.SerialDevice):
raise exceptions.InvalidResponse('\n'.join(data))
expected_checksum = int(checksum_match.group('checksum'), 16)
- # exclude the last line in the checksum calculation, as that's the checksum
- # itself. The final \r\n is added separately.
- calculated_checksum = sum(ord(c) for c in '\r\n'.join(data[:-1])) + 0xd + 0xa
+ # exclude the last line in the checksum calculation, as that's the
+ # checksum itself. The final \r\n is added separately.
+ calculated_checksum = sum(
+ ord(c) for c in '\r\n'.join(data[:-1])) + 0xd + 0xa
if expected_checksum != calculated_checksum:
- raise exceptions.InvalidChecksum(expected_checksum, calculated_checksum)
+ raise exceptions.InvalidChecksum(
+ expected_checksum, calculated_checksum)
for line in data[5:-1]:
match = _READING_RE.match(line)
@@ -257,7 +259,8 @@ class Device(serial.SerialDevice):
raise exceptions.InvalidResponse(line)
if match.group('type') != 'G':
- logging.warning('Non-glucose readings are not supported, ignoring.')
+ logging.warning(
+ 'Non-glucose readings are not supported, ignoring.')
continue
if match.group('reading') == 'HI ':
@@ -273,6 +276,6 @@ class Device(serial.SerialDevice):
timestamp = datetime.datetime(year, month, day, hour, minute)
- # The reading, if present, is always in mg/dL even if the glucometer is
- # set to mmol/L.
+ # The reading, if present, is always in mg/dL even if the glucometer
+ # is set to mmol/L.
yield common.GlucoseReading(timestamp, value)