Skip to content

Commit

Permalink
FreeStyle Libre: implement glucose unit identificaton.
Browse files Browse the repository at this point in the history
The suspected `$uom?` command was finally confirmed to be the correct
command to identify the unit of measure used.
  • Loading branch information
Flameeyes committed Aug 3, 2023
1 parent ba0faf1 commit fcd0d5f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions glucometerutils/support/freestyle_libre.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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?
Expand Down Expand Up @@ -218,9 +218,13 @@ def get_serial_number(self) -> str:

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
Expand Down

0 comments on commit fcd0d5f

Please sign in to comment.