Add fitbit nutrition sensors (#101626)
* Add fitbit nutrition sensors * Add test coverage for unit systems
This commit is contained in:
parent
d3a67cd984
commit
7d202f78f5
3 changed files with 112 additions and 0 deletions
|
@ -33,6 +33,7 @@ from homeassistant.const import (
|
|||
UnitOfLength,
|
||||
UnitOfMass,
|
||||
UnitOfTime,
|
||||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
@ -122,6 +123,13 @@ def _elevation_unit(unit_system: FitbitUnitSystem) -> UnitOfLength:
|
|||
return UnitOfLength.METERS
|
||||
|
||||
|
||||
def _water_unit(unit_system: FitbitUnitSystem) -> UnitOfVolume:
|
||||
"""Determine the water unit."""
|
||||
if unit_system == FitbitUnitSystem.EN_US:
|
||||
return UnitOfVolume.FLUID_OUNCES
|
||||
return UnitOfVolume.MILLILITERS
|
||||
|
||||
|
||||
@dataclass
|
||||
class FitbitSensorEntityDescription(SensorEntityDescription):
|
||||
"""Describes Fitbit sensor entity."""
|
||||
|
@ -453,6 +461,24 @@ FITBIT_RESOURCES_LIST: Final[tuple[FitbitSensorEntityDescription, ...]] = (
|
|||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
FitbitSensorEntityDescription(
|
||||
key="foods/log/caloriesIn",
|
||||
name="Calories In",
|
||||
native_unit_of_measurement="cal",
|
||||
icon="mdi:food-apple",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
scope="nutrition",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
FitbitSensorEntityDescription(
|
||||
key="foods/log/water",
|
||||
name="Water",
|
||||
icon="mdi:cup-water",
|
||||
unit_fn=_water_unit,
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
scope="nutrition",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
)
|
||||
|
||||
# Different description depending on clock format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue