Allen Porter bd2fee289d
Update Fitbit integration to allow UI based configuration (#100897)
* 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>
2023-09-30 16:56:39 -07:00

81 lines
2.1 KiB
Python

"""Constants for the Fitbit platform."""
from __future__ import annotations
from enum import StrEnum
from typing import Final
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
DOMAIN: Final = "fitbit"
ATTR_ACCESS_TOKEN: Final = "access_token"
ATTR_REFRESH_TOKEN: Final = "refresh_token"
ATTR_LAST_SAVED_AT: Final = "last_saved_at"
ATTR_DURATION: Final = "duration"
ATTR_DISTANCE: Final = "distance"
ATTR_ELEVATION: Final = "elevation"
ATTR_HEIGHT: Final = "height"
ATTR_WEIGHT: Final = "weight"
ATTR_BODY: Final = "body"
ATTR_LIQUIDS: Final = "liquids"
ATTR_BLOOD_GLUCOSE: Final = "blood glucose"
ATTR_BATTERY: Final = "battery"
CONF_MONITORED_RESOURCES: Final = "monitored_resources"
CONF_CLOCK_FORMAT: Final = "clock_format"
ATTRIBUTION: Final = "Data provided by Fitbit.com"
FITBIT_AUTH_CALLBACK_PATH: Final = "/api/fitbit/callback"
FITBIT_AUTH_START: Final = "/api/fitbit"
FITBIT_CONFIG_FILE: Final = "fitbit.conf"
FITBIT_DEFAULT_RESOURCES: Final[list[str]] = ["activities/steps"]
DEFAULT_CONFIG: Final[dict[str, str]] = {
CONF_CLIENT_ID: "CLIENT_ID_HERE",
CONF_CLIENT_SECRET: "CLIENT_SECRET_HERE",
}
DEFAULT_CLOCK_FORMAT: Final = "24H"
BATTERY_LEVELS: Final[dict[str, int]] = {
"High": 100,
"Medium": 50,
"Low": 20,
"Empty": 0,
}
class FitbitUnitSystem(StrEnum):
"""Fitbit unit system set when sending requests to the Fitbit API.
This is used as a header to tell the Fitbit API which type of units to return.
https://dev.fitbit.com/build/reference/web-api/developer-guide/application-design/#Units
Prefer to leave unset for newer configurations to use the Home Assistant default units.
"""
LEGACY_DEFAULT = "default"
"""When set, will use an appropriate default using a legacy algorithm."""
METRIC = "metric"
"""Use metric units."""
EN_US = "en_US"
"""Use United States units."""
EN_GB = "en_GB"
"""Use United Kingdom units."""
OAUTH2_AUTHORIZE = "https://www.fitbit.com/oauth2/authorize"
OAUTH2_TOKEN = "https://api.fitbit.com/oauth2/token"
OAUTH_SCOPES = [
"activity",
"heartrate",
"nutrition",
"profile",
"settings",
"sleep",
"weight",
]