From 50c8b19f42c58931af69f2f68f2bbb6ed076cd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Thu, 3 Aug 2023 10:12:46 +0100 Subject: FreeStyle Libre: implement glucose unit identificaton. The suspected `$uom?` command was finally confirmed to be the correct command to identify the unit of measure used. --- glucometerutils/support/freestyle_libre.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/glucometerutils/support/freestyle_libre.py b/glucometerutils/support/freestyle_libre.py index e5c9efe..46ecf15 100644 --- a/glucometerutils/support/freestyle_libre.py +++ b/glucometerutils/support/freestyle_libre.py @@ -14,7 +14,7 @@ import datetime import logging from typing import Dict, Generator, Mapping, Optional, Sequence, Tuple, Type -from glucometerutils import common +from glucometerutils import common, exceptions from glucometerutils.support import freestyle # Fields of the records returned by both $history and $arresult? @@ -218,9 +218,13 @@ class LibreDevice(freestyle.FreeStyleHidDevice): def get_glucose_unit(self) -> common.Unit: # pylint: disable=no-self-use """Returns the glucose unit of the device.""" - # TODO(Flameeyes): figure out how to identify the actual unit on the - # device. - return common.Unit.MG_DL + uom = self._session.send_text_command(b"$uom?").rstrip("\r\n") + if uom == "0": + return common.Unit.MMOL_L + if uom == "1": + return common.Unit.MG_DL + + raise exceptions.InvalidGlucoseUnit(uom) def get_readings(self) -> Generator[common.AnyReading, None, None]: # First of all get the usually longer list of sensor readings, and -- cgit v1.2.3