text: """The Strava integration."""
  from __future__ import annotations
  
  import logging
  
  import voluptuous as vol
  
  from homeassistant.config_entries import ConfigEntry
  from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
  from homeassistant.core import HomeAssistant
  from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
  from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
  
  from . import config_flow
  from .const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN, SCAN_INTERVAL
  from .strava_api import StravaAPI
  
  CONFIG_SCHEMA = vol.Schema(
      {
          DOMAIN: vol.Schema(
              {
                  vol.Required(CONF_CLIENT_ID): cv.string,
                  vol.Required(CONF_CLIENT_SECRET): cv.string,
              }
          )
      },
      extra=vol.ALLOW_EXTRA,
  )
  
  _LOGGER = logging.getLogger(__name__)
  _LOGGER.setLevel(logging.DEBUG)
  
  PLATFORMS: list[Platform] = [Platform.SENSOR]
  
  
  async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
      """Set up Strava from a config entry."""
      hass.data.setdefault(DOMAIN, {})
  
      # OAuth Stuff
      try:
          implementation = (
              await config_entry_oauth2_flow.async_get_config_entry_implementation(
                  hass, entry
              )
          )
      except ValueError:
          implementation = config_entry_oauth2_flow.LocalOAuth2Implementation(
              hass,
              DOMAIN,
              entry.data[CONF_CLIENT_ID],
              entry.data[CONF_CLIENT_SECRET],
              OAUTH2_AUTHORIZE,
              OAUTH2_TOKEN,
          )
  
          config_flow.OAuth2FlowHandler.async_register_implementation(
              hass, implementation
          )
  
      session = config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
  
      await session.async_ensure_token_valid()
  
      async def async_update_data():
          strava = StravaAPI(session)
          data = await strava.fetch_strava_data()
          return data
  
      coordinator = DataUpdateCoordinator(
          hass,
          _LOGGER,
          name=f"Strava Ride",
          update_method=async_update_data,
          update_interval=SCAN_INTERVAL,
      )
  
      await coordinator.async_config_entry_first_refresh()
  
      hass.data.setdefault(DOMAIN, {})
      hass.data[DOMAIN][entry.entry_id] = coordinator
  
      hass.config_entries.async_setup_platforms(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
  