Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions custom_components/libreview/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,32 @@ 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

@property
def get_mmol_l_value(self) -> float:
if self.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]:
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),
"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
),
Expand Down