Add fitbit nutrition sensors (#101626)

* Add fitbit nutrition sensors

* Add test coverage for unit systems
This commit is contained in:
Allen Porter 2023-10-08 01:09:26 -07:00 committed by GitHub
parent d3a67cd984
commit 7d202f78f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 0 deletions

View file

@ -14,6 +14,11 @@ from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity
from homeassistant.util.unit_system import (
METRIC_SYSTEM,
US_CUSTOMARY_SYSTEM,
UnitSystem,
)
from .conftest import (
DEVICES_API_URL,
@ -426,6 +431,39 @@ async def test_heartrate_scope_config_entry(
}
@pytest.mark.parametrize(
("scopes", "unit_system"),
[(["nutrition"], METRIC_SYSTEM), (["nutrition"], US_CUSTOMARY_SYSTEM)],
)
async def test_nutrition_scope_config_entry(
hass: HomeAssistant,
setup_credentials: None,
integration_setup: Callable[[], Awaitable[bool]],
register_timeseries: Callable[[str, dict[str, Any]], None],
unit_system: UnitSystem,
snapshot: SnapshotAssertion,
) -> None:
"""Test nutrition sensors are enabled."""
hass.config.units = unit_system
register_timeseries(
"foods/log/water",
timeseries_response("foods-log-water", "99"),
)
register_timeseries(
"foods/log/caloriesIn",
timeseries_response("foods-log-caloriesIn", "1600"),
)
assert await integration_setup()
state = hass.states.get("sensor.water")
assert state
assert (state.state, state.attributes) == snapshot
state = hass.states.get("sensor.calories_in")
assert state
assert (state.state, state.attributes) == snapshot
@pytest.mark.parametrize(
("scopes"),
[(["sleep"])],