mirror of
https://github.com/home-assistant/core.git
synced 2025-05-30 02:37:04 +00:00

* Cleanup fitbit sensor API parsing * Remove API code that is not used yet * Configuration flow for fitbit * Code cleanup after manual review * Streamline code for review * Use scopes to determine which entities to enable * Use set for entity comparisons * Apply fitbit string pr feedback * Improve fitbit configuration flow error handling * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Fix typo in more places * Revert typing import * Revert custom domain back to default * Add additional config flow tests * Add breaks_in_ha_version to repair issues * Update homeassistant/components/fitbit/api.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Increase test coverage for token refresh success case * Add breaks_in_ha_version for sensor issue * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Simplify translations, issue keys, and token refresh * Config flow test improvements * Simplify repair issue creation on fitbit import * Remove unused strings --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""The fitbit component."""
|
|
|
|
import aiohttp
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
from homeassistant.helpers import config_entry_oauth2_flow
|
|
|
|
from . import api
|
|
from .const import DOMAIN
|
|
|
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up fitbit from a config entry."""
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
implementation = (
|
|
await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
|
hass, entry
|
|
)
|
|
)
|
|
session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
|
|
fitbit_api = api.OAuthFitbitApi(
|
|
hass, session, unit_system=entry.data.get("unit_system")
|
|
)
|
|
try:
|
|
await fitbit_api.async_get_access_token()
|
|
except aiohttp.ClientError as err:
|
|
raise ConfigEntryNotReady from err
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = fitbit_api
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|