summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2019-07-01 21:49:29 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.com>2019-07-01 21:49:29 +0200
commit783ae018c61526f1b5e88f8d82e87c2955ba82bb (patch)
tree769bbd8ced4e2984a8615c6ae6d661f7ea97d970
parenthandle device.get_datetime() value error exception (diff)
downloadglucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar.gz
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar.bz2
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar.lz
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar.xz
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.tar.zst
glucometerutils-783ae018c61526f1b5e88f8d82e87c2955ba82bb.zip
-rw-r--r--glucometerutils/exceptions.py8
-rwxr-xr-xglucometerutils/glucometer.py6
-rw-r--r--glucometerutils/support/freestyle.py8
3 files changed, 18 insertions, 4 deletions
diff --git a/glucometerutils/exceptions.py b/glucometerutils/exceptions.py
index 415c97f..1cc8cfd 100644
--- a/glucometerutils/exceptions.py
+++ b/glucometerutils/exceptions.py
@@ -46,3 +46,11 @@ class InvalidGlucoseUnit(Error):
def __init__(self, unit):
super(InvalidGlucoseUnit, self).__init__(
'Invalid glucose unit received:\n%s' % unit)
+
+
+class InvalidDateTime(Error):
+ """The device has an invalid date/time setting."""
+
+ def __init__(self):
+ super(InvalidDateTime, self).__init__(
+ 'Invalid date and time for device')
diff --git a/glucometerutils/glucometer.py b/glucometerutils/glucometer.py
index 485b32b..14999a7 100755
--- a/glucometerutils/glucometer.py
+++ b/glucometerutils/glucometer.py
@@ -86,9 +86,9 @@ def main():
if args.action == 'info':
try:
time_str = device.get_datetime()
- except ValueError:
- time_str = 'N/A' #handles value error exception for when time format found isn't expected
- except NotImplementedError:
+ except exceptions.InvalidDateTime:
+ time_str = 'INVALID'
+ except NotImplementedError, ValueError: # Catch any leftover ValueError
time_str = 'N/A'
print("{device_info}Time: {time}".format(
device_info=str(device_info), time=time_str))
diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py
index d18a81f..475d6f5 100644
--- a/glucometerutils/support/freestyle.py
+++ b/glucometerutils/support/freestyle.py
@@ -200,7 +200,13 @@ class FreeStyleHidDevice(hiddevice.HidDevice):
month, day, year = (int(x) for x in date.split(','))
hour, minute = (int(x) for x in time.split(','))
- return datetime.datetime(year + 2000, month, day, hour, minute)
+ # At least Precision Neo devices can have an invalid date (bad RTC?),
+ # and report 255 for each field, which is not valid for
+ # datetime.datetime().
+ try:
+ return datetime.datetime(year + 2000, month, day, hour, minute)
+ except ValueError:
+ raise exceptions.InvalidDateTime()
def set_datetime(self, date=datetime.datetime.now()):
# type: (datetime.datetime) -> datetime.datetime