mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Use SOURCE_REAUTH constant for starting reauth flows (#48553)
This commit is contained in:
parent
68801ae5f7
commit
6cf57da89f
@ -8,6 +8,7 @@ from pyatv.const import Protocol
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import (
|
||||
CONF_ADDRESS,
|
||||
CONF_NAME,
|
||||
@ -34,8 +35,6 @@ BACKOFF_TIME_UPPER_LIMIT = 300 # Five minutes
|
||||
NOTIFICATION_TITLE = "Apple TV Notification"
|
||||
NOTIFICATION_ID = "apple_tv_notification"
|
||||
|
||||
SOURCE_REAUTH = "reauth"
|
||||
|
||||
SIGNAL_CONNECTED = "apple_tv_connected"
|
||||
SIGNAL_DISCONNECTED = "apple_tv_disconnected"
|
||||
|
||||
|
@ -8,7 +8,7 @@ from yalexs.exceptions import AugustApiAIOHTTPError
|
||||
from yalexs.pubnub_activity import activities_from_pubnub_message
|
||||
from yalexs.pubnub_async import AugustPubNub, async_create_pubnub
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, HTTP_UNAUTHORIZED
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
|
||||
@ -60,7 +60,7 @@ def _async_start_reauth(hass: HomeAssistant, entry: ConfigEntry):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -8,6 +8,7 @@ from async_timeout import timeout
|
||||
from python_awair import Awair
|
||||
from python_awair.exceptions import AuthError
|
||||
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
@ -74,7 +75,7 @@ class AwairDataUpdateCoordinator(DataUpdateCoordinator):
|
||||
return {result.device.uuid: result for result in results}
|
||||
except AuthError as err:
|
||||
flow_context = {
|
||||
"source": "reauth",
|
||||
"source": SOURCE_REAUTH,
|
||||
"unique_id": self._config_entry.unique_id,
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ from homeassistant.components.azure_devops.const import (
|
||||
DATA_AZURE_DEVOPS_CLIENT,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -16,6 +16,7 @@ from homeassistant.components.blink.const import (
|
||||
SERVICE_SAVE_VIDEO,
|
||||
SERVICE_SEND_PIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import CONF_FILENAME, CONF_NAME, CONF_PIN, CONF_SCAN_INTERVAL
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -49,7 +50,7 @@ def _reauth_flow_wrapper(hass, data):
|
||||
"""Reauth flow wrapper."""
|
||||
hass.add_job(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "reauth"}, data=data
|
||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=data
|
||||
)
|
||||
)
|
||||
persistent_notification.async_create(
|
||||
|
@ -14,6 +14,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.dhcp import IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_TIMEOUT, CONF_TYPE
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
@ -107,7 +108,7 @@ class BroadlinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
else:
|
||||
device.timeout = timeout
|
||||
|
||||
if self.source != "reauth":
|
||||
if self.source != SOURCE_REAUTH:
|
||||
await self.async_set_device(device)
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_HOST: device.host[0], CONF_TIMEOUT: timeout}
|
||||
|
@ -13,6 +13,7 @@ from broadlink.exceptions import (
|
||||
NetworkTimeoutError,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_TIMEOUT, CONF_TYPE
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
@ -171,7 +172,7 @@ class BroadlinkDevice:
|
||||
self.hass.async_create_task(
|
||||
self.hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data={CONF_NAME: self.name, **self.config.data},
|
||||
)
|
||||
)
|
||||
|
@ -10,7 +10,7 @@ import async_timeout
|
||||
from ovoenergy import OVODailyUsage
|
||||
from ovoenergy.ovoenergy import OVOEnergy
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
if not authenticated:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "reauth"}, data=entry.data
|
||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=entry.data
|
||||
)
|
||||
)
|
||||
return False
|
||||
@ -63,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
if not authenticated:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "reauth"}, data=entry.data
|
||||
DOMAIN, context={"source": SOURCE_REAUTH}, data=entry.data
|
||||
)
|
||||
)
|
||||
raise UpdateFailed("Not authenticated with OVO Energy")
|
||||
|
@ -11,7 +11,7 @@ from tesla_powerwall import (
|
||||
PowerwallUnreachableError,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -185,7 +185,7 @@ def _async_start_reauth(hass: HomeAssistant, entry: ConfigEntry):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -18,6 +18,7 @@ from homeassistant.components.media_player.const import (
|
||||
SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_ID,
|
||||
@ -124,7 +125,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
||||
self.hass.add_job(
|
||||
self.hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=self._config_entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -12,7 +12,7 @@ from sharkiqpy import (
|
||||
SharkIqVacuum,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
@ -76,7 +76,7 @@ class SharkIqUpdateCoordinator(DataUpdateCoordinator):
|
||||
) as err:
|
||||
_LOGGER.debug("Bad auth state. Attempting re-auth", exc_info=err)
|
||||
flow_context = {
|
||||
"source": "reauth",
|
||||
"source": SOURCE_REAUTH,
|
||||
"unique_id": self._config_entry.unique_id,
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
|
||||
from homeassistant.components.spotify import config_flow
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import ATTR_CREDENTIALS, CONF_CLIENT_ID, CONF_CLIENT_SECRET
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
@ -87,7 +87,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -9,7 +9,7 @@ from teslajsonpy import Controller as TeslaAPI
|
||||
from teslajsonpy.exceptions import IncompleteCredentials, TeslaException
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_CHARGING,
|
||||
ATTR_BATTERY_LEVEL,
|
||||
@ -220,7 +220,7 @@ def _async_start_reauth(hass: HomeAssistant, entry: ConfigEntry):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": "reauth"},
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
|
@ -28,7 +28,7 @@ from withings_api.common import (
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_WEBHOOK_ID,
|
||||
HTTP_UNAUTHORIZED,
|
||||
@ -740,7 +740,7 @@ class DataManager:
|
||||
context = {
|
||||
const.PROFILE: self._profile,
|
||||
"userid": self._user_id,
|
||||
"source": "reauth",
|
||||
"source": SOURCE_REAUTH,
|
||||
}
|
||||
|
||||
# Check if reauth flow already exists.
|
||||
|
@ -8,6 +8,7 @@ from withings_api.common import AuthScope
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.withings import const
|
||||
from homeassistant.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.util import slugify
|
||||
|
||||
@ -51,7 +52,7 @@ class WithingsFlowHandler(
|
||||
errors = {}
|
||||
reauth_profile = (
|
||||
self.context.get(const.PROFILE)
|
||||
if self.context.get("source") == "reauth"
|
||||
if self.context.get("source") == SOURCE_REAUTH
|
||||
else None
|
||||
)
|
||||
profile = data.get(const.PROFILE) or reauth_profile
|
||||
|
Loading…
x
Reference in New Issue
Block a user