Add entity translations to Dexcom (#98795)
This commit is contained in:
parent
57bc8ae68e
commit
f10a5b7ee8
3 changed files with 29 additions and 36 deletions
|
@ -38,6 +38,8 @@ async def async_setup_entry(
|
|||
class DexcomSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
"""Base Dexcom sensor entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, username: str, entry_id: str, key: str
|
||||
) -> None:
|
||||
|
@ -54,6 +56,7 @@ class DexcomGlucoseValueSensor(DexcomSensorEntity):
|
|||
"""Representation of a Dexcom glucose value sensor."""
|
||||
|
||||
_attr_icon = GLUCOSE_VALUE_ICON
|
||||
_attr_translation_key = "glucose_value"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -66,7 +69,6 @@ class DexcomGlucoseValueSensor(DexcomSensorEntity):
|
|||
super().__init__(coordinator, username, entry_id, "value")
|
||||
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"
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
|
@ -79,12 +81,13 @@ class DexcomGlucoseValueSensor(DexcomSensorEntity):
|
|||
class DexcomGlucoseTrendSensor(DexcomSensorEntity):
|
||||
"""Representation of a Dexcom glucose trend sensor."""
|
||||
|
||||
_attr_translation_key = "glucose_trend"
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, username: str, entry_id: str
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, username, entry_id, "trend")
|
||||
self._attr_name = f"{DOMAIN}_{username}_glucose_trend"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -28,5 +28,15 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"glucose_value": {
|
||||
"name": "Glucose value"
|
||||
},
|
||||
"glucose_trend": {
|
||||
"name": "Glucose trend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
"""Test we get sensor data."""
|
||||
await init_integration(hass)
|
||||
|
||||
test_username_glucose_value = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_value"
|
||||
)
|
||||
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
||||
assert test_username_glucose_value.state == str(GLUCOSE_READING.value)
|
||||
test_username_glucose_trend = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_trend"
|
||||
)
|
||||
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
||||
assert test_username_glucose_trend.state == GLUCOSE_READING.trend_description
|
||||
|
||||
|
||||
|
@ -37,16 +33,12 @@ async def test_sensors_unknown(hass: HomeAssistant) -> None:
|
|||
"homeassistant.components.dexcom.Dexcom.get_current_glucose_reading",
|
||||
return_value=None,
|
||||
):
|
||||
await async_update_entity(hass, "sensor.dexcom_test_username_glucose_value")
|
||||
await async_update_entity(hass, "sensor.dexcom_test_username_glucose_trend")
|
||||
await async_update_entity(hass, "sensor.test_username_glucose_value")
|
||||
await async_update_entity(hass, "sensor.test_username_glucose_trend")
|
||||
|
||||
test_username_glucose_value = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_value"
|
||||
)
|
||||
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
||||
assert test_username_glucose_value.state == STATE_UNKNOWN
|
||||
test_username_glucose_trend = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_trend"
|
||||
)
|
||||
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
||||
assert test_username_glucose_trend.state == STATE_UNKNOWN
|
||||
|
||||
|
||||
|
@ -58,16 +50,12 @@ async def test_sensors_update_failed(hass: HomeAssistant) -> None:
|
|||
"homeassistant.components.dexcom.Dexcom.get_current_glucose_reading",
|
||||
side_effect=SessionError,
|
||||
):
|
||||
await async_update_entity(hass, "sensor.dexcom_test_username_glucose_value")
|
||||
await async_update_entity(hass, "sensor.dexcom_test_username_glucose_trend")
|
||||
await async_update_entity(hass, "sensor.test_username_glucose_value")
|
||||
await async_update_entity(hass, "sensor.test_username_glucose_trend")
|
||||
|
||||
test_username_glucose_value = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_value"
|
||||
)
|
||||
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
||||
assert test_username_glucose_value.state == STATE_UNAVAILABLE
|
||||
test_username_glucose_trend = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_trend"
|
||||
)
|
||||
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
||||
assert test_username_glucose_trend.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
|
@ -75,13 +63,9 @@ async def test_sensors_options_changed(hass: HomeAssistant) -> None:
|
|||
"""Test we handle sensor unavailable."""
|
||||
entry = await init_integration(hass)
|
||||
|
||||
test_username_glucose_value = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_value"
|
||||
)
|
||||
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
||||
assert test_username_glucose_value.state == str(GLUCOSE_READING.value)
|
||||
test_username_glucose_trend = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_trend"
|
||||
)
|
||||
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
||||
assert test_username_glucose_trend.state == GLUCOSE_READING.trend_description
|
||||
|
||||
with patch(
|
||||
|
@ -99,11 +83,7 @@ async def test_sensors_options_changed(hass: HomeAssistant) -> None:
|
|||
|
||||
assert entry.options == {CONF_UNIT_OF_MEASUREMENT: MMOL_L}
|
||||
|
||||
test_username_glucose_value = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_value"
|
||||
)
|
||||
test_username_glucose_value = hass.states.get("sensor.test_username_glucose_value")
|
||||
assert test_username_glucose_value.state == str(GLUCOSE_READING.mmol_l)
|
||||
test_username_glucose_trend = hass.states.get(
|
||||
"sensor.dexcom_test_username_glucose_trend"
|
||||
)
|
||||
test_username_glucose_trend = hass.states.get("sensor.test_username_glucose_trend")
|
||||
assert test_username_glucose_trend.state == GLUCOSE_READING.trend_description
|
||||
|
|
Loading…
Add table
Reference in a new issue