summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2021-03-03 19:11:53 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-03-03 19:16:18 +0100
commitc6c752040afd3e670ebe7471001df100c95765d4 (patch)
tree0ccd57199c0512a59b8e154b5ff807126564cc61
parentfslibre: add a debug log for the retrieved arresults. (diff)
downloadglucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar.gz
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar.bz2
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar.lz
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar.xz
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.tar.zst
glucometerutils-c6c752040afd3e670ebe7471001df100c95765d4.zip
-rw-r--r--glucometerutils/drivers/fslibre.py2
-rw-r--r--glucometerutils/support/freestyle.py13
-rw-r--r--setup.py6
3 files changed, 13 insertions, 8 deletions
diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py
index 79025f6..c11bab0 100644
--- a/glucometerutils/drivers/fslibre.py
+++ b/glucometerutils/drivers/fslibre.py
@@ -211,7 +211,7 @@ class Device(freestyle.FreeStyleHidDevice):
"""Glucometer driver for FreeStyle Libre devices."""
def __init__(self, device_path: Optional[str]) -> None:
- super().__init__(0x3650, device_path)
+ super().__init__(0x3650, device_path, encoding="utf-8")
def get_meter_info(self) -> common.MeterInfo:
"""Return the device information in structured form."""
diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py
index 28aec6a..b74d4b8 100644
--- a/glucometerutils/support/freestyle.py
+++ b/glucometerutils/support/freestyle.py
@@ -50,17 +50,20 @@ class FreeStyleHidDevice(driver.GlucometerDevice):
device_path: Optional[str],
text_cmd: int = 0x60,
text_reply_cmd: int = 0x60,
+ encoding: str = "ascii",
) -> None:
super().__init__(device_path)
+ self._encoding = encoding
try:
self._session = freestyle_hid.Session(
product_id,
pathlib.Path(device_path) if device_path else None,
text_cmd,
text_reply_cmd,
+ encoding=encoding,
)
except Exception as e:
- raise exceptions.ConnectionFailed(str(e))
+ raise exceptions.ConnectionFailed(str(e)) from e
def connect(self) -> None:
"""Open connection to the device, starting the knocking sequence."""
@@ -92,9 +95,11 @@ class FreeStyleHidDevice(driver.GlucometerDevice):
def set_patient_name(self, name: str) -> None:
try:
- encoded_name = name.encode("ascii")
- except UnicodeDecodeError:
- raise ValueError("Only ASCII-safe names are tested working")
+ encoded_name = name.encode(self._encoding)
+ except UnicodeDecodeError as error:
+ raise ValueError(
+ f"Error encoding patient name to {self._encoding}."
+ ) from error
self._session.send_text_command(b"$ptname," + encoded_name)
diff --git a/setup.py b/setup.py
index 98e1c85..e629ae0 100644
--- a/setup.py
+++ b/setup.py
@@ -12,10 +12,10 @@ extras_require = {
# listed as mandatory for the feature.
"accucheck_reports": [],
"contourusb": ["construct", "hidapi"],
- "fsinsulinx": ["freestyle-hid"],
- "fslibre": ["freestyle-hid"],
+ "fsinsulinx": ["freestyle-hid>=1.0.2"],
+ "fslibre": ["freestyle-hid>=1.0.2"],
"fsoptium": ["pyserial"],
- "fsprecisionneo": ["freestyle-hid"],
+ "fsprecisionneo": ["freestyle-hid>=1.0.2"],
"otultra2": ["pyserial"],
"otultraeasy": ["construct", "pyserial"],
"otverio2015": ["construct", "PYSCSI[sgio]>=2.0.1"],