Drop self._key, and move to class attribute

This commit is contained in:
epenet 2024-11-13 14:00:01 +00:00
parent a0e96258bf
commit e6a0407da8

View file

@ -71,6 +71,9 @@ class DexcomGlucoseValueSensor(DexcomSensorEntity):
"""Representation of a Dexcom glucose value sensor.""" """Representation of a Dexcom glucose value sensor."""
_attr_device_class = SensorDeviceClass.BLOOD_GLUCOSE_CONCENTRATION _attr_device_class = SensorDeviceClass.BLOOD_GLUCOSE_CONCENTRATION
_attr_native_unit_of_measurement = (
UnitOfBloodGlucoseConcentration.MILLIGRAMS_PER_DECILITER
)
_attr_translation_key = "glucose_value" _attr_translation_key = "glucose_value"
def __init__( def __init__(
@ -81,16 +84,12 @@ class DexcomGlucoseValueSensor(DexcomSensorEntity):
) -> None: ) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
super().__init__(coordinator, username, entry_id, "value") super().__init__(coordinator, username, entry_id, "value")
self._key = "mg_dl"
self._attr_native_unit_of_measurement = (
UnitOfBloodGlucoseConcentration.MILLIGRAMS_PER_DECILITER
)
@property @property
def native_value(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self.coordinator.data: if self.coordinator.data:
return getattr(self.coordinator.data, self._key) return self.coordinator.data.mg_dl
return None return None