Make Dexcom use shorthand attributes (#95231)
This commit is contained in:
parent
7add36d847
commit
4ab8411145
1 changed files with 9 additions and 41 deletions
|
@ -32,44 +32,23 @@ async def async_setup_entry(
|
|||
class DexcomGlucoseValueSensor(CoordinatorEntity, SensorEntity):
|
||||
"""Representation of a Dexcom glucose value sensor."""
|
||||
|
||||
_attr_icon = GLUCOSE_VALUE_ICON
|
||||
|
||||
def __init__(self, coordinator, username, unit_of_measurement):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._state = None
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._attribute_unit_of_measurement = (
|
||||
"mg_dl" if unit_of_measurement == MG_DL else "mmol_l"
|
||||
)
|
||||
self._name = f"{DOMAIN}_{username}_glucose_value"
|
||||
self._unique_id = f"{username}-value"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon for the frontend."""
|
||||
return GLUCOSE_VALUE_ICON
|
||||
|
||||
@property
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of the device."""
|
||||
return self._unit_of_measurement
|
||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||
self._key = "mg_dl" if unit_of_measurement == MG_DL else "mmol_l"
|
||||
self._attr_name = f"{DOMAIN}_{username}_glucose_value"
|
||||
self._attr_unique_id = f"{username}-value"
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self.coordinator.data:
|
||||
return getattr(self.coordinator.data, self._attribute_unit_of_measurement)
|
||||
return getattr(self.coordinator.data, self._key)
|
||||
return None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device unique id."""
|
||||
return self._unique_id
|
||||
|
||||
|
||||
class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
||||
"""Representation of a Dexcom glucose trend sensor."""
|
||||
|
@ -77,14 +56,8 @@ class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
|||
def __init__(self, coordinator, username):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._state = None
|
||||
self._name = f"{DOMAIN}_{username}_glucose_trend"
|
||||
self._unique_id = f"{username}-trend"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
self._attr_name = f"{DOMAIN}_{username}_glucose_trend"
|
||||
self._attr_unique_id = f"{username}-trend"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
@ -99,8 +72,3 @@ class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
|||
if self.coordinator.data:
|
||||
return self.coordinator.data.trend_description
|
||||
return None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device unique id."""
|
||||
return self._unique_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue