diff options
author | Ben <b-schaefer@posteo.de> | 2020-02-18 18:14:56 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-02-18 19:53:22 +0100 |
commit | 649a12b906f8310b46f0e0d88374446abd1632e1 (patch) | |
tree | c1b48bd3cc32ba64f982956f914506b3dda16245 /glucometerutils/support | |
parent | Bugfix: get current time within the function (diff) | |
download | glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar.gz glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar.bz2 glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar.lz glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar.xz glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.tar.zst glucometerutils-649a12b906f8310b46f0e0d88374446abd1632e1.zip |
Diffstat (limited to 'glucometerutils/support')
-rw-r--r-- | glucometerutils/support/driver_base.py | 55 | ||||
-rw-r--r-- | glucometerutils/support/freestyle.py | 16 |
2 files changed, 61 insertions, 10 deletions
diff --git a/glucometerutils/support/driver_base.py b/glucometerutils/support/driver_base.py new file mode 100644 index 0000000..b7b3d0f --- /dev/null +++ b/glucometerutils/support/driver_base.py @@ -0,0 +1,55 @@ +from abc import ABC, abstractmethod +from datetime import datetime + + +class GlucometerDriver(ABC): + + def connect(self): + pass + + def disconnect(self): + pass + + @abstractmethod + def get_meter_info(self): + """Return the device information in structured form.""" + pass + + @abstractmethod + def get_serial_number(self): + pass + + @abstractmethod + def get_glucose_unit(self): + """Returns the glucose unit of the device.""" + pass + + @abstractmethod + def get_datetime(self): + pass + + def set_datetime(self, date=None): + """Sets the date and time of the glucometer. + + Args: + date: The value to set the date/time of the glucometer to. If none is + given, the current date and time of the computer is used. + + Returns: + A datetime object built according to the returned response. + """ + if not date: + date = datetime.now() + return self._set_device_datetime(date) + + @abstractmethod + def _set_device_datetime(self, date): + pass + + @abstractmethod + def zero_log(self): + pass + + @abstractmethod + def get_readings(self): + pass diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index ed8f7e9..1e8c097 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -12,12 +12,13 @@ import csv import datetime import logging import re +from abc import ABC from typing import AnyStr, Callable, Iterator, List, Optional, Text, Tuple import construct from glucometerutils import exceptions -from glucometerutils.support import hiddevice +from glucometerutils.support import hiddevice, driver_base _INIT_COMMAND = 0x01 _INIT_RESPONSE = 0x71 @@ -103,6 +104,7 @@ def _verify_checksum(message, expected_checksum_hex): if expected_checksum != calculated_checksum: raise exceptions.InvalidChecksum(expected_checksum, calculated_checksum) + def convert_ketone_unit(raw_value): """Convert raw ketone value as read in the device to its value in mmol/L. @@ -113,7 +115,8 @@ def convert_ketone_unit(raw_value): """ return raw_value / 18.0 -class FreeStyleHidDevice(hiddevice.HidDevice): + +class FreeStyleHidDevice(hiddevice.HidDevice, driver_base.GlucometerDriver, ABC): """Base class implementing the FreeStyle HID common protocol. This class implements opening, initializing the connection and sending @@ -295,12 +298,9 @@ class FreeStyleHidDevice(hiddevice.HidDevice): except ValueError: raise exceptions.InvalidDateTime() - def set_datetime(self, date=None): + def _set_device_datetime(self, date): # type: (datetime.datetime) -> datetime.datetime - """Sets the date and time of the device.""" - if not date: - date = datetime.datetime.now() # The format used by the FreeStyle devices is not composable based on # standard strftime() (namely it includes no leading zeros), so we need # to build it manually. @@ -314,10 +314,6 @@ class FreeStyleHidDevice(hiddevice.HidDevice): return self.get_datetime() - def zero_log(self): - """Not implemented, Abbott devices don't allow resetting memory.""" - raise NotImplementedError - def _get_multirecord(self, command): # type: (bytes) -> Iterator[List[Text]] """Queries for, and returns, "multirecords" results. |