diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-03-26 19:56:13 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2020-03-26 20:00:32 +0100 |
commit | 9433599de3d9c8e10a9985e3c40a7eb35eeb784d (patch) | |
tree | e78c28234f22713e1d9a0ca0bc5f55a658a5e602 /glucometerutils/support | |
parent | Update the local Emacs config to match the black/isort/flake8 configs. (diff) | |
download | glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar.gz glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar.bz2 glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar.lz glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar.xz glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.tar.zst glucometerutils-9433599de3d9c8e10a9985e3c40a7eb35eeb784d.zip |
Diffstat (limited to 'glucometerutils/support')
-rw-r--r-- | glucometerutils/support/contourusb.py | 13 | ||||
-rw-r--r-- | glucometerutils/support/freestyle.py | 6 |
2 files changed, 7 insertions, 12 deletions
diff --git a/glucometerutils/support/contourusb.py b/glucometerutils/support/contourusb.py index 6cd9442..876c534 100644 --- a/glucometerutils/support/contourusb.py +++ b/glucometerutils/support/contourusb.py @@ -11,16 +11,10 @@ http://protocols.ascensia.com/Programming-Guide.aspx """ -import csv import datetime -import logging import re -from typing import Dict, Iterator, List, Optional, Text, Tuple +from typing import Dict, List, Optional, Text, Tuple -import construct - -from glucometerutils import exceptions -from glucometerutils.exceptions import InvalidResponse from glucometerutils.support import driver_base, hiddevice # regexr.com/4k6jb @@ -88,7 +82,8 @@ class ContourHidDevice(driver_base.GlucometerDriver): while True: data = self._hid_session.read() dstr = data - result.append(dstr[4 : data[3] + 4]) + data_end_idx = data[3] + 4 + result.append(dstr[4:data_end_idx]) if data[3] != self.blocksize - 4: break @@ -308,7 +303,7 @@ class ContourHidDevice(driver_base.GlucometerDriver): result = self.checkframe(data[stx:]) tometer = "\x06" self.state = self.mode_data - except FrameError as e: + except FrameError: tometer = "\x15" # Couldn't parse, <NAK> else: # Got something we don't understand, <NAK> it diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py index b1eb2d2..c77282b 100644 --- a/glucometerutils/support/freestyle.py +++ b/glucometerutils/support/freestyle.py @@ -12,7 +12,6 @@ import csv import datetime import logging import re -from abc import ABC from typing import AnyStr, Callable, Iterator, List, Optional, Text, Tuple import construct @@ -185,7 +184,8 @@ class FreeStyleHidSession: if not encrypted or message_type in _ALWAYS_UNENCRYPTED_MESSAGES: message_length = usb_packet[1] - message_content = usb_packet[2 : 2 + message_length] + message_end_idx = 2 + message_length + message_content = usb_packet[2:message_end_idx] else: message_content = usb_packet[1:] @@ -340,7 +340,7 @@ class FreeStyleHidDevice(driver_base.GlucometerDriver): except UnicodeDecodeError: raise ValueError("Only ASCII-safe names are tested working") - result = self._session.send_text_command(b"$ptname," + encoded_name) + self._session.send_text_command(b"$ptname," + encoded_name) def get_datetime(self): # type: () -> datetime.datetime |