From 6e979fbe39658de2d60ff393361cf3979f6011d1 Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:23:15 +0100 Subject: [PATCH 1/7] Fix mmol/l value when native value of the app is set to mg/dl Turns out that the .value returned from the api is not always in mmol/l as assumed. Instead it seems to be the native value that the libre app is set to. So we calculate the mmol/l ourselves from the fixed mg/dl value provided --- custom_components/libreview/sensor.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index 6e6a747..618a68a 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -136,15 +136,18 @@ def name(self) -> str: def native_value(self) -> int | float | None: """Return the state of the entity.""" if self.uom == GlucoseUnitOfMeasurement.MMOLL: - return self.gcm.value + return self.get_mmol_l_value if self.uom == GlucoseUnitOfMeasurement.MGDL: return self.gcm.value_in_mg_per_dl return None + def get_mmol_l_value(self) -> float: + return self.gcm_value_in_mg_per_dl / 18.0 + @property def extra_state_attributes(self) -> Dict[str, int | float]: return { - "value_mmol_l": self.gcm.value, + "value_mmol_l": self.get_mmol_l_value "value_mg_dl": self.gcm.value_in_mg_per_dl, "target_high_mmol_l": round(self.connection.target_high / 18, 1), "target_low_mmol_l": round(self.connection.target_low / 18, 1), From 96ee4a6d8acddd7e3509a012c2d0dec45622f0c8 Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:25:03 +0100 Subject: [PATCH 2/7] Missing comma --- custom_components/libreview/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index 618a68a..fb223e5 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -147,7 +147,7 @@ def get_mmol_l_value(self) -> float: @property def extra_state_attributes(self) -> Dict[str, int | float]: return { - "value_mmol_l": self.get_mmol_l_value + "value_mmol_l": self.get_mmol_l_value, "value_mg_dl": self.gcm.value_in_mg_per_dl, "target_high_mmol_l": round(self.connection.target_high / 18, 1), "target_low_mmol_l": round(self.connection.target_low / 18, 1), From 7718946016619eb2b7c77c0f9a8dac398ef476ad Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:33:09 +0100 Subject: [PATCH 3/7] Add get_mmol_l_value property to sensor --- custom_components/libreview/sensor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index fb223e5..a16e938 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -140,7 +140,8 @@ def native_value(self) -> int | float | None: if self.uom == GlucoseUnitOfMeasurement.MGDL: return self.gcm.value_in_mg_per_dl return None - + + @property def get_mmol_l_value(self) -> float: return self.gcm_value_in_mg_per_dl / 18.0 From 49eeed8a6a536034175c33894cab2a125ea95391 Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:34:29 +0100 Subject: [PATCH 4/7] Fix formatting in sensor.py --- custom_components/libreview/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index a16e938..c86b08b 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -140,7 +140,7 @@ def native_value(self) -> int | float | None: if self.uom == GlucoseUnitOfMeasurement.MGDL: return self.gcm.value_in_mg_per_dl return None - + @property def get_mmol_l_value(self) -> float: return self.gcm_value_in_mg_per_dl / 18.0 From fa2e67c073f914111bc4d1df54ecadbcc0535fda Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:47:36 +0100 Subject: [PATCH 5/7] Enhance sensor.py with unit of measurement handling Add app_uom property and update get_mmol_l_value method to handle unit of measurement. --- custom_components/libreview/sensor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index c86b08b..1c4c91c 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -143,7 +143,13 @@ def native_value(self) -> int | float | None: @property def get_mmol_l_value(self) -> float: - return self.gcm_value_in_mg_per_dl / 18.0 + if (app_uom == 1): + return self.gcm_value_in_mg_per_dl / 18.0 + return self.gcm.value + + @property + def app_uom(self) -> int: + return self.connection.uom @property def extra_state_attributes(self) -> Dict[str, int | float]: @@ -155,6 +161,7 @@ def extra_state_attributes(self) -> Dict[str, int | float]: "target_high_mg_dl": self.connection.target_high, "target_low_mg_dl": self.connection.target_low, "trend": TREND_MESSAGE.get(self.trend_arrow, "unknown"), + "app_unit_of_measurement": "mmol/L" if self.app_uom == 0 else "mg/dL" "measurement_timestamp": self.gcm.factory_timestamp.replace( tzinfo=timezone.utc ), From aed7c780d2a1f0d99e05aba4638cad9cbf37e656 Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:48:34 +0100 Subject: [PATCH 6/7] Fix syntax error in sensor.py --- custom_components/libreview/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index 1c4c91c..49beb72 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -161,7 +161,7 @@ def extra_state_attributes(self) -> Dict[str, int | float]: "target_high_mg_dl": self.connection.target_high, "target_low_mg_dl": self.connection.target_low, "trend": TREND_MESSAGE.get(self.trend_arrow, "unknown"), - "app_unit_of_measurement": "mmol/L" if self.app_uom == 0 else "mg/dL" + "app_unit_of_measurement": "mmol/L" if self.app_uom == 0 else "mg/dL", "measurement_timestamp": self.gcm.factory_timestamp.replace( tzinfo=timezone.utc ), From 6d7cdd08c9b75329244b90d9c3d29fe8c9293d0d Mon Sep 17 00:00:00 2001 From: Patrick Toft Steffensen <17211264+PTST@users.noreply.github.com> Date: Fri, 20 Feb 2026 07:49:40 +0100 Subject: [PATCH 7/7] Fix reference to app_uom in get_mmol_l_value --- custom_components/libreview/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/libreview/sensor.py b/custom_components/libreview/sensor.py index 49beb72..7a8036b 100644 --- a/custom_components/libreview/sensor.py +++ b/custom_components/libreview/sensor.py @@ -143,7 +143,7 @@ def native_value(self) -> int | float | None: @property def get_mmol_l_value(self) -> float: - if (app_uom == 1): + if self.app_uom == 1: return self.gcm_value_in_mg_per_dl / 18.0 return self.gcm.value