From bc2d1a0ee33acb339a20e6ffcd4e5e7a28fa260d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sun, 7 Jul 2019 22:10:14 +0100 Subject: fslibre: expose patient name if the device knows it. This includes extension of the base info command to report this when asked on the command line. --- glucometerutils/common.py | 11 +++++++++-- glucometerutils/drivers/fslibre.py | 3 ++- glucometerutils/support/freestyle.py | 9 ++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/glucometerutils/common.py b/glucometerutils/common.py index a258e4b..4af2001 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -8,7 +8,7 @@ import enum import textwrap try: - from typing import Sequence, Text + from typing import Optional, Sequence, Text except ImportError: pass @@ -131,6 +131,7 @@ class MeterInfo: version_info = attr.ib(default=()) # type: Sequence[Text] native_unit = attr.ib( default=Unit.MG_DL, validator=attr.validators.in_(Unit)) # type: Unit + patient_name = attr.ib(default=None) # type: Optional[Text] def __str__(self): version_information_string = 'N/A' @@ -138,7 +139,7 @@ class MeterInfo: version_information_string = '\n '.join( self.version_info).strip() - return textwrap.dedent("""\ + base_output = textwrap.dedent("""\ {model} Serial Number: {serial_number} Version Information: @@ -147,3 +148,9 @@ class MeterInfo: """).format(model=self.model, serial_number=self.serial_number, version_information_string=version_information_string, native_unit=self.native_unit.value) + + if self.patient_name != None: + base_output += 'Patient Name: {patient_name}\n'.format( + patient_name=self.patient_name) + + return base_output diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index 85bfdab..87a6556 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -208,7 +208,8 @@ class Device(freestyle.FreeStyleHidDevice): serial_number=self.get_serial_number(), version_info=( 'Software version: ' + self._get_version(),), - native_unit=self.get_glucose_unit()) + native_unit=self.get_glucose_unit(), + patient_name=self.get_patient_name()) def get_serial_number(self): """Overridden function as the command is not compatible.""" diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index 475d6f5..4684194 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -14,7 +14,7 @@ import logging import re try: - from typing import Iterator, List, Text, Tuple + from typing import Iterator, List, Optional, Text, Tuple except ImportError: pass @@ -186,6 +186,13 @@ class FreeStyleHidDevice(hiddevice.HidDevice): """Returns the serial number of the device.""" return self._send_text_command(b'$serlnum?').rstrip('\r\n') + def get_patient_name(self): + # type: () -> Optional[Text] + patient_name = self._send_text_command(b'$ptname?').rstrip('\r\n') + if not patient_name: + return None + return patient_name + def get_datetime(self): # type: () -> datetime.datetime """Gets the date and time as reported by the device. -- cgit v1.2.3