mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Add base entity for Dexcom (#98158)
This commit is contained in:
parent
3e1d2a1000
commit
b9203cbeaf
@ -6,7 +6,10 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT, CONF_USERNAME
|
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import COORDINATOR, DOMAIN, GLUCOSE_TREND_ICON, GLUCOSE_VALUE_ICON, MG_DL
|
from .const import COORDINATOR, DOMAIN, GLUCOSE_TREND_ICON, GLUCOSE_VALUE_ICON, MG_DL
|
||||||
|
|
||||||
@ -29,18 +32,33 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DexcomGlucoseValueSensor(CoordinatorEntity, SensorEntity):
|
class DexcomSensorEntity(CoordinatorEntity, SensorEntity):
|
||||||
|
"""Base Dexcom sensor entity."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, coordinator: DataUpdateCoordinator, username: str, key: str
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self._attr_unique_id = f"{username}-{key}"
|
||||||
|
|
||||||
|
|
||||||
|
class DexcomGlucoseValueSensor(DexcomSensorEntity):
|
||||||
"""Representation of a Dexcom glucose value sensor."""
|
"""Representation of a Dexcom glucose value sensor."""
|
||||||
|
|
||||||
_attr_icon = GLUCOSE_VALUE_ICON
|
_attr_icon = GLUCOSE_VALUE_ICON
|
||||||
|
|
||||||
def __init__(self, coordinator, username, unit_of_measurement):
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: DataUpdateCoordinator,
|
||||||
|
username: str,
|
||||||
|
unit_of_measurement: str,
|
||||||
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator, username, "value")
|
||||||
self._attr_native_unit_of_measurement = 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._key = "mg_dl" if unit_of_measurement == MG_DL else "mmol_l"
|
||||||
self._attr_name = f"{DOMAIN}_{username}_glucose_value"
|
self._attr_name = f"{DOMAIN}_{username}_glucose_value"
|
||||||
self._attr_unique_id = f"{username}-value"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
@ -50,14 +68,13 @@ class DexcomGlucoseValueSensor(CoordinatorEntity, SensorEntity):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class DexcomGlucoseTrendSensor(CoordinatorEntity, SensorEntity):
|
class DexcomGlucoseTrendSensor(DexcomSensorEntity):
|
||||||
"""Representation of a Dexcom glucose trend sensor."""
|
"""Representation of a Dexcom glucose trend sensor."""
|
||||||
|
|
||||||
def __init__(self, coordinator, username):
|
def __init__(self, coordinator: DataUpdateCoordinator, username: str) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator, username, "trend")
|
||||||
self._attr_name = f"{DOMAIN}_{username}_glucose_trend"
|
self._attr_name = f"{DOMAIN}_{username}_glucose_trend"
|
||||||
self._attr_unique_id = f"{username}-trend"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user