diff options
-rw-r--r-- | glucometerutils/drivers/fslibre.py | 3 | ||||
-rwxr-xr-x | glucometerutils/glucometer.py | 22 | ||||
-rw-r--r-- | glucometerutils/support/freestyle.py | 9 |
3 files changed, 33 insertions, 1 deletions
diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index 87a6556..2823a2b 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -6,7 +6,8 @@ Supported features: - get readings (sensor, flash and blood glucose), including comments; - get and set date and time; - - get serial number and software version. + - get serial number and software version; + - get and set patient name. Expected device path: /dev/hidraw9 or similar HID device. Optional when using HIDAPI. diff --git a/glucometerutils/glucometer.py b/glucometerutils/glucometer.py index 8cf2555..8f222bc 100755 --- a/glucometerutils/glucometer.py +++ b/glucometerutils/glucometer.py @@ -58,6 +58,12 @@ def main(): '--set', action='store', nargs='?', const='now', default=None, help='Set the date rather than just reading it from the device.') + parser_patient = subparsers.add_parser( + 'patient', help='Reads or sets the patient information.') + parser_patient.add_argument( + '--set_name', action='store', required=False, + help='Set the patient name, if the meter supports it.') + args = parser.parse_args() logging.basicConfig(level=args.vlog) @@ -124,6 +130,22 @@ def main(): print(device.set_datetime(new_date)) else: print(device.get_datetime()) + elif args.action == 'patient': + if args.set_name != None: + try: + device.set_patient_name(args.set_name) + except NotImplementedError: + print( + 'The glucometer does not support setting patient name.') + try: + patient_name = device.get_patient_name() + if patient_name is None: + patient_name = '[N/A]' + print('Patient Name: {patient_name}'.format( + patient_name=patient_name)) + except NotImplementedError: + print( + 'The glucometer does not support retrieving patient name.') elif args.action == 'zero': confirm = input('Delete the device data log? (y/N) ') if confirm.lower() in ['y', 'ye', 'yes']: diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index 4684194..13674df 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -193,6 +193,15 @@ class FreeStyleHidDevice(hiddevice.HidDevice): return None return patient_name + def set_patient_name(self, name): + # type: (Text) -> None + try: + name = name.encode('ascii') + except UnicodeDecodeError: + raise ValueError('Only ASCII-safe names are tested working') + + result = self._send_text_command(b'$ptname,' + name) + def get_datetime(self): # type: () -> datetime.datetime """Gets the date and time as reported by the device. |