From ad7538a019718d89691935028379e2aba94cdfa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sun, 15 Jan 2017 13:22:09 +0000 Subject: Fetch the device information in all commands. It's usually cheap and can provide assurance the device is connected and the right type. --- glucometer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/glucometer.py b/glucometer.py index 1cb263d..8e19237 100755 --- a/glucometer.py +++ b/glucometer.py @@ -54,18 +54,20 @@ def main(): device = driver.Device(args.device) device.connect() + device_info = device.get_meter_info() try: if args.action == 'info': - print(str(device.get_meter_info()).strip()) try: - print('Time: %s' % device.get_datetime()) + time_str = device.get_datetime() except NotImplementedError: - print('Time: N/A') + time_str = 'N/A' + print("{device_info}Time: {time}".format( + device_info=str(device_info), time=time_str)) elif args.action == 'dump': unit = args.unit if unit is None: - unit = device.get_glucose_unit() + unit = device_info.native_unit readings = device.get_readings() -- cgit v1.2.3