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):
|
class DexcomGlucoseValueSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Dexcom glucose value sensor."""
|
"""Representation of a Dexcom glucose value sensor."""
|
||||||
|
|
||||||
|
_attr_icon = GLUCOSE_VALUE_ICON
|
||||||
|
|
||||||
def __init__(self, coordinator, username, unit_of_measurement):
|
def __init__(self, coordinator, username, unit_of_measurement):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._state = None
|
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._key = "mg_dl" if unit_of_measurement == MG_DL else "mmol_l"
|
||||||
self._attribute_unit_of_measurement = (
|
self._attr_name = f"{DOMAIN}_{username}_glucose_value"
|
||||||
"mg_dl" if unit_of_measurement == MG_DL else "mmol_l"
|
self._attr_unique_id = f"{username}-value"
|
||||||
)
|
|
||||||
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
|
|
||||||
|
|
||||||
@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._attribute_unit_of_measurement)
|
return getattr(self.coordinator.data, self._key)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Device unique id."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
|
|
||||||
class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Representation of a Dexcom glucose trend sensor."""
|
"""Representation of a Dexcom glucose trend sensor."""
|
||||||
|
@ -77,14 +56,8 @@ class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
||||||
def __init__(self, coordinator, username):
|
def __init__(self, coordinator, username):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._state = None
|
self._attr_name = f"{DOMAIN}_{username}_glucose_trend"
|
||||||
self._name = f"{DOMAIN}_{username}_glucose_trend"
|
self._attr_unique_id = f"{username}-trend"
|
||||||
self._unique_id = f"{username}-trend"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
@ -99,8 +72,3 @@ class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
||||||
if self.coordinator.data:
|
if self.coordinator.data:
|
||||||
return self.coordinator.data.trend_description
|
return self.coordinator.data.trend_description
|
||||||
return None
|
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