mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Clean up twitch setup (#110849)
* Clean up twitch setup * Clean up twitch setup
This commit is contained in:
parent
babb436512
commit
e2ab44903c
@ -1,14 +1,17 @@
|
||||
"""The Twitch component."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import cast
|
||||
|
||||
from aiohttp.client_exceptions import ClientError, ClientResponseError
|
||||
from twitchAPI.twitch import Twitch
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_TOKEN
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||
LocalOAuth2Implementation,
|
||||
OAuth2Session,
|
||||
async_get_config_entry_implementation,
|
||||
)
|
||||
@ -18,7 +21,10 @@ from .const import DOMAIN, OAUTH_SCOPES, PLATFORMS
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Twitch from a config entry."""
|
||||
implementation = await async_get_config_entry_implementation(hass, entry)
|
||||
implementation = cast(
|
||||
LocalOAuth2Implementation,
|
||||
await async_get_config_entry_implementation(hass, entry),
|
||||
)
|
||||
session = OAuth2Session(hass, entry, implementation)
|
||||
try:
|
||||
await session.async_ensure_token_valid()
|
||||
@ -31,10 +37,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except ClientError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
app_id = implementation.__dict__[CONF_CLIENT_ID]
|
||||
access_token = entry.data[CONF_TOKEN][CONF_ACCESS_TOKEN]
|
||||
client = await Twitch(
|
||||
app_id=app_id,
|
||||
app_id=implementation.client_id,
|
||||
authenticate_app=False,
|
||||
)
|
||||
client.auto_refresh_auth = False
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import Any, cast
|
||||
|
||||
from twitchAPI.helper import first
|
||||
from twitchAPI.twitch import Twitch
|
||||
@ -14,6 +14,7 @@ from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_TOKEN
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
||||
from homeassistant.data_entry_flow import AbortFlow, FlowResult
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.helpers.config_entry_oauth2_flow import LocalOAuth2Implementation
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
|
||||
from .const import CONF_CHANNELS, CONF_REFRESH_TOKEN, DOMAIN, LOGGER, OAUTH_SCOPES
|
||||
@ -47,9 +48,13 @@ class OAuth2FlowHandler(
|
||||
data: dict[str, Any],
|
||||
) -> FlowResult:
|
||||
"""Handle the initial step."""
|
||||
implementation = cast(
|
||||
LocalOAuth2Implementation,
|
||||
self.flow_impl,
|
||||
)
|
||||
|
||||
client = await Twitch(
|
||||
app_id=self.flow_impl.__dict__[CONF_CLIENT_ID],
|
||||
app_id=implementation.client_id,
|
||||
authenticate_app=False,
|
||||
)
|
||||
client.auto_refresh_auth = False
|
||||
|
Loading…
x
Reference in New Issue
Block a user