diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2017-01-15 14:10:23 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2017-01-15 14:10:23 +0100 |
commit | 7ceeddc76323e921f06e707717090d88df9e915f (patch) | |
tree | 7c1ddcdfbc37b9c86a8ea1518d1f0c02c9b74806 | |
parent | Add a submodule pointing at gdef, to start implementing gdef export. (diff) | |
download | glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar.gz glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar.bz2 glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar.lz glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar.xz glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.tar.zst glucometerutils-7ceeddc76323e921f06e707717090d88df9e915f.zip |
Diffstat (limited to '')
-rwxr-xr-x | glucometer.py | 6 | ||||
-rw-r--r-- | glucometerutils/common.py | 34 | ||||
-rw-r--r-- | glucometerutils/drivers/accuchek_reports.py | 12 | ||||
-rw-r--r-- | glucometerutils/drivers/freestyle_optium.py | 22 | ||||
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 22 | ||||
-rw-r--r-- | glucometerutils/drivers/otultraeasy.py | 17 | ||||
-rw-r--r-- | glucometerutils/drivers/otverio2015.py | 18 | ||||
-rw-r--r-- | glucometerutils/drivers/sdcodefree.py | 4 |
8 files changed, 78 insertions, 57 deletions
diff --git a/glucometer.py b/glucometer.py index e22ff23..1cb263d 100755 --- a/glucometer.py +++ b/glucometer.py @@ -57,7 +57,11 @@ def main(): try: if args.action == 'info': - print(device.get_information_string()) + print(str(device.get_meter_info()).strip()) + try: + print('Time: %s' % device.get_datetime()) + except NotImplementedError: + print('Time: N/A') elif args.action == 'dump': unit = args.unit if unit is None: diff --git a/glucometerutils/common.py b/glucometerutils/common.py index 32402a6..1e7e7f8 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -7,6 +7,7 @@ __copyright__ = 'Copyright © 2013, Diego Elio Pettenò' __license__ = 'MIT' import collections +import textwrap from glucometerutils import exceptions @@ -82,3 +83,36 @@ class Reading(_ReadingBase): to_unit: (UNIT_MGDL|UNIT_MMOLL) The unit to return the value to. """ return convert_glucose_unit(self.value, UNIT_MGDL, to_unit) + +_MeterInfoBase = collections.namedtuple( + '_MeterInfoBase', ['model', 'serial_number', 'version_info', 'native_unit']) + +class MeterInfo(_MeterInfoBase): + def __new__(cls, model, serial_number='N/A', version_info=(), + native_unit=UNIT_MGDL): + """Construct a meter information object. + + Args: + model: (string) Human-readable model name, depending on driver. + serial_number: (string) Optional serial number to identify the device. + version_info: (list(string)) Optional hardware/software version information. + native_unit: (UNIT_MGDL|UNIT_MMOLL) Native unit of the device for display. + """ + return super(MeterInfo, cls).__new__( + cls, model=model, serial_number=serial_number, version_info=version_info, + native_unit=native_unit) + + def __str__(self): + version_information_string = 'N/A' + if self.version_info: + version_information_string = '\n '.join(self.version_info).strip() + + return textwrap.dedent("""\ + {model} + Serial Number: {serial_number} + Version Information: + {version_information_string} + Native Unit: {native_unit} + """).format(model=self.model, serial_number=self.serial_number, + version_information_string=version_information_string, + native_unit=self.native_unit) diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py index 941491e..f200471 100644 --- a/glucometerutils/drivers/accuchek_reports.py +++ b/glucometerutils/drivers/accuchek_reports.py @@ -68,13 +68,11 @@ class Device(object): def disconnect(self): self.report.close() - def get_information_string(self): - return ('%s glucometer\n' - 'Serial number: %s\n' - 'Default unit: %s' % ( - self.get_model(), - self.get_serial_number(), - self.get_glucose_unit())) + def get_meter_info(self): + return common.MeterInfo( + '%s glucometer' % self.get_model(), + serial_number=self.get_serial_number(), + native_unit=self.get_glucose_unit()) def get_model(self): # $device/MODEL/Reports/*.csv diff --git a/glucometerutils/drivers/freestyle_optium.py b/glucometerutils/drivers/freestyle_optium.py index 8a20657..0b20946 100644 --- a/glucometerutils/drivers/freestyle_optium.py +++ b/glucometerutils/drivers/freestyle_optium.py @@ -127,22 +127,18 @@ class Device(object): # the commands and not replying to them. raise exceptions.ConnectionFailed() - def get_information_string(self): - """Returns a single string with all the identification information. + def get_meter_info(self): + """Fetch and parses the device information. Returns: - A string including the serial number, software version, date and time and - default unit. + A common.MeterInfo object. """ - return ('Freestyle Optium glucometer\n' - 'Serial number: %s\n' - 'Software version: %s\n' - 'Time: %s\n' - 'Default unit: %s' % ( - self.get_serial_number(), - self.get_version(), - self.get_datetime(), - self.get_glucose_unit())) + 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()) def get_version(self): """Returns an identifier of the firmware version of the glucometer. diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 9647947..b484f6b 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -159,22 +159,18 @@ class Device(object): line = self.serial_.readline().decode('ascii') return _validate_and_strip_checksum(line) - def get_information_string(self): - """Returns a single string with all the identification information. + def get_meter_info(self): + """Fetch and parses the device information. Returns: - A string including the serial number, software version, date and time and - default unit. + A common.MeterInfo object. """ - return ('OneTouch Ultra 2 glucometer\n' - 'Serial number: %s\n' - 'Software version: %s\n' - 'Time: %s\n' - 'Default unit: %s' % ( - self.get_serial_number(), - self.get_version(), - self.get_datetime(), - self.get_glucose_unit())) + return common.MeterInfo( + 'OneTouch Ultra 2 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. diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py index f7d0270..4a61fe6 100644 --- a/glucometerutils/drivers/otultraeasy.py +++ b/glucometerutils/drivers/otultraeasy.py @@ -231,16 +231,13 @@ class Device(object): result = self._read_response() return result - def get_information_string(self): - return ('OneTouch Ultra Easy glucometer\n' - 'Serial number: %s\n' - 'Software version: %s\n' - 'Time: %s\n' - 'Default unit: %s' % ( - self.get_serial_number(), - self.get_version(), - self.get_datetime(), - self.get_glucose_unit())) + def get_meter_info(self): + return common.MeterInfo( + 'OneTouch Ultra Easy glucometer', + serial_number=self.get_serial_number(), + version_info=( + 'Software version: ' + self.get_version(),), + native_unit=self.get_glucose_unit()) def get_version(self): result = self._send_command(_READ_VERSION) diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py index e794e92..3e4c81b 100644 --- a/glucometerutils/drivers/otverio2015.py +++ b/glucometerutils/drivers/otverio2015.py @@ -132,17 +132,13 @@ class Device(object): def disconnect(self): return - def get_information_string(self): - return ('OneTouch %s glucometer\n' - 'Serial number: %s\n' - 'Software version: %s\n' - 'Time: %s\n' - 'Default unit: %s\n' % ( - self._query_string(_QUERY_KEY_MODEL), - self.get_serial_number(), - self.get_version(), - self.get_datetime(), - self.get_glucose_unit())) + def get_meter_info(self): + return common.MeterInfo( + 'OneTouch %s glucometer' % self._query_string(_QUERY_KEY_MODEL), + serial_number=self.get_serial_number(), + version_info=( + 'Software version: ' + self.get_version(),), + native_unit=self.get_glucose_unit()) def _query_string(self, query_key): response = self._send_message(_QUERY_REQUEST + query_key, 3) diff --git a/glucometerutils/drivers/sdcodefree.py b/glucometerutils/drivers/sdcodefree.py index ec232dd..e7ce753 100644 --- a/glucometerutils/drivers/sdcodefree.py +++ b/glucometerutils/drivers/sdcodefree.py @@ -141,8 +141,8 @@ class Device(object): if response != _DISCONNECTED_PACKET: raise exceptions.InvalidResponse(response=response) - def get_information_string(self): - return ('SD CodeFree glucometer\n') + def get_meter_info(self): + return common.MeterInfo('SD CodeFree glucometer') def get_version(self): raise NotImplementedError |