mirror of
https://github.com/home-assistant/core.git
synced 2026-11-06 13:41:27 -04:00
Update Fitbit to avoid a KeyError when restingHeartRate is not present (#103872)
* Update Fitbit to avoid a KeyError when `restingHeartRate` is not present * Explicitly handle none response values
This commit is contained in:
@@ -771,3 +771,60 @@ async def test_device_battery_level_reauth_required(
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
assert len(flows) == 1
|
||||
assert flows[0]["step_id"] == "reauth_confirm"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("scopes", "response_data", "expected_state"),
|
||||
[
|
||||
(["heartrate"], {}, "unknown"),
|
||||
(
|
||||
["heartrate"],
|
||||
{
|
||||
"restingHeartRate": 120,
|
||||
},
|
||||
"120",
|
||||
),
|
||||
(
|
||||
["heartrate"],
|
||||
{
|
||||
"restingHeartRate": 0,
|
||||
},
|
||||
"0",
|
||||
),
|
||||
],
|
||||
ids=("missing", "valid", "zero"),
|
||||
)
|
||||
async def test_resting_heart_rate_responses(
|
||||
hass: HomeAssistant,
|
||||
setup_credentials: None,
|
||||
integration_setup: Callable[[], Awaitable[bool]],
|
||||
register_timeseries: Callable[[str, dict[str, Any]], None],
|
||||
response_data: dict[str, Any],
|
||||
expected_state: str,
|
||||
) -> None:
|
||||
"""Test resting heart rate sensor with various values from response."""
|
||||
|
||||
register_timeseries(
|
||||
"activities/heart",
|
||||
timeseries_response(
|
||||
"activities-heart",
|
||||
{
|
||||
"customHeartRateZones": [],
|
||||
"heartRateZones": [
|
||||
{
|
||||
"caloriesOut": 0,
|
||||
"max": 220,
|
||||
"min": 159,
|
||||
"minutes": 0,
|
||||
"name": "Peak",
|
||||
},
|
||||
],
|
||||
**response_data,
|
||||
},
|
||||
),
|
||||
)
|
||||
assert await integration_setup()
|
||||
|
||||
state = hass.states.get("sensor.resting_heart_rate")
|
||||
assert state
|
||||
assert state.state == expected_state
|
||||
|
||||
Reference in New Issue
Block a user