Use CONF_CLIENT_ID & CONF_CLIENT_SECRET from homeassistant.const (#36233)

* Use CONF_CLIENT_ID & CONF_CLIENT_SECRET from homeassistant.const

* Fix pylint

* Use in tests

* Search for "client_id"

* Fix tests

* Fix test

* Fix test
This commit is contained in:
Quentame 2020-05-30 17:27:20 +02:00 committed by GitHub
parent b6407f77da
commit 1855c91988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 386 additions and 352 deletions

View File

@ -3,15 +3,13 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_NAME
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv, entityfilter from homeassistant.helpers import config_validation as cv, entityfilter
from . import flash_briefings, intent, smart_home_http from . import flash_briefings, intent, smart_home_http
from .const import ( from .const import (
CONF_AUDIO, CONF_AUDIO,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_DESCRIPTION, CONF_DESCRIPTION,
CONF_DISPLAY_CATEGORIES, CONF_DISPLAY_CATEGORIES,
CONF_DISPLAY_URL, CONF_DISPLAY_URL,

View File

@ -7,7 +7,7 @@ import logging
import aiohttp import aiohttp
import async_timeout import async_timeout
from homeassistant.const import HTTP_OK from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, HTTP_OK
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client from homeassistant.helpers import aiohttp_client
from homeassistant.util import dt from homeassistant.util import dt
@ -48,8 +48,8 @@ class Auth:
lwa_params = { lwa_params = {
"grant_type": "authorization_code", "grant_type": "authorization_code",
"code": accept_grant_code, "code": accept_grant_code,
"client_id": self.client_id, CONF_CLIENT_ID: self.client_id,
"client_secret": self.client_secret, CONF_CLIENT_SECRET: self.client_secret,
} }
_LOGGER.debug( _LOGGER.debug(
"Calling LWA to get the access token (first time), with: %s", "Calling LWA to get the access token (first time), with: %s",
@ -80,8 +80,8 @@ class Auth:
lwa_params = { lwa_params = {
"grant_type": "refresh_token", "grant_type": "refresh_token",
"refresh_token": self._prefs[STORAGE_REFRESH_TOKEN], "refresh_token": self._prefs[STORAGE_REFRESH_TOKEN],
"client_id": self.client_id, CONF_CLIENT_ID: self.client_id,
"client_secret": self.client_secret, CONF_CLIENT_SECRET: self.client_secret,
} }
_LOGGER.debug("Calling LWA to refresh the access token.") _LOGGER.debug("Calling LWA to refresh the access token.")

View File

@ -18,8 +18,6 @@ CONF_DISPLAY_URL = "display_url"
CONF_FILTER = "filter" CONF_FILTER = "filter"
CONF_ENTITY_CONFIG = "entity_config" CONF_ENTITY_CONFIG = "entity_config"
CONF_ENDPOINT = "endpoint" CONF_ENDPOINT = "endpoint"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_LOCALE = "locale" CONF_LOCALE = "locale"
ATTR_UID = "uid" ATTR_UID = "uid"

View File

@ -3,17 +3,11 @@ import logging
from homeassistant import core from homeassistant import core
from homeassistant.components.http.view import HomeAssistantView from homeassistant.components.http.view import HomeAssistantView
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from .auth import Auth from .auth import Auth
from .config import AbstractConfig from .config import AbstractConfig
from .const import ( from .const import CONF_ENDPOINT, CONF_ENTITY_CONFIG, CONF_FILTER, CONF_LOCALE
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_ENDPOINT,
CONF_ENTITY_CONFIG,
CONF_FILTER,
CONF_LOCALE,
)
from .smart_home import async_handle_message from .smart_home import async_handle_message
from .state_report import async_enable_proactive_mode from .state_report import async_enable_proactive_mode

View File

@ -13,7 +13,13 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.auth.const import GROUP_ID_ADMIN
from homeassistant.components import conversation from homeassistant.components import conversation
from homeassistant.const import CONF_HOST, CONF_TYPE, EVENT_HOMEASSISTANT_START from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_HOST,
CONF_TYPE,
EVENT_HOMEASSISTANT_START,
)
from homeassistant.core import Context, CoreState, HomeAssistant from homeassistant.core import Context, CoreState, HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import ( from homeassistant.helpers import (
@ -29,9 +35,6 @@ from homeassistant.helpers import (
from . import config_flow from . import config_flow
from .const import DOMAIN, TYPE_LOCAL, TYPE_OAUTH2 from .const import DOMAIN, TYPE_LOCAL, TYPE_OAUTH2
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
STORAGE_VERSION = 1 STORAGE_VERSION = 1
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN

View File

@ -3,10 +3,11 @@ import logging
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from . import config_flow from . import config_flow
from .const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, DOMAIN from .const import DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -11,14 +11,18 @@ from homeassistant.components.climate.const import (
HVAC_MODE_OFF, HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE,
) )
from homeassistant.const import ATTR_NAME, ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import (
ATTR_NAME,
ATTR_TEMPERATURE,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
TEMP_CELSIUS,
)
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import ( from .const import (
ATTR_VALUE, ATTR_VALUE,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DOMAIN, DOMAIN,
SERVICE_COMFORT_FEEDBACK, SERVICE_COMFORT_FEEDBACK,
SERVICE_COMFORT_MODE, SERVICE_COMFORT_MODE,

View File

@ -5,6 +5,7 @@ import ambiclimate
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.network import get_url from homeassistant.helpers.network import get_url
@ -12,8 +13,6 @@ from homeassistant.helpers.network import get_url
from .const import ( from .const import (
AUTH_CALLBACK_NAME, AUTH_CALLBACK_NAME,
AUTH_CALLBACK_PATH, AUTH_CALLBACK_PATH,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DOMAIN, DOMAIN,
STORAGE_KEY, STORAGE_KEY,
STORAGE_VERSION, STORAGE_VERSION,

View File

@ -1,12 +1,13 @@
"""Constants used by the Ambiclimate component.""" """Constants used by the Ambiclimate component."""
ATTR_VALUE = "value"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
DOMAIN = "ambiclimate" DOMAIN = "ambiclimate"
ATTR_VALUE = "value"
SERVICE_COMFORT_FEEDBACK = "send_comfort_feedback" SERVICE_COMFORT_FEEDBACK = "send_comfort_feedback"
SERVICE_COMFORT_MODE = "set_comfort_mode" SERVICE_COMFORT_MODE = "set_comfort_mode"
SERVICE_TEMPERATURE_MODE = "set_temperature_mode" SERVICE_TEMPERATURE_MODE = "set_temperature_mode"
STORAGE_KEY = "ambiclimate_auth" STORAGE_KEY = "ambiclimate_auth"
STORAGE_VERSION = 1 STORAGE_VERSION = 1

View File

@ -10,19 +10,17 @@ from homeassistant.components.device_tracker import (
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
DeviceScanner, DeviceScanner,
) )
from homeassistant.const import CONF_API_KEY, CONF_HOST from homeassistant.const import CONF_API_KEY, CONF_CLIENT_ID, CONF_HOST
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
SCAN_INTERVAL = timedelta(seconds=120) SCAN_INTERVAL = timedelta(seconds=120)
CLIENT_ID = "client_id"
GRANT_TYPE = "client_credentials" GRANT_TYPE = "client_credentials"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
vol.Required(CONF_HOST): cv.string, vol.Required(CONF_HOST): cv.string,
vol.Required(CLIENT_ID): cv.string, vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_API_KEY): cv.string, vol.Required(CONF_API_KEY): cv.string,
} }
) )
@ -37,7 +35,7 @@ def get_scanner(hass, config):
"server": config[DOMAIN][CONF_HOST], "server": config[DOMAIN][CONF_HOST],
"grant_type": GRANT_TYPE, "grant_type": GRANT_TYPE,
"secret": config[DOMAIN][CONF_API_KEY], "secret": config[DOMAIN][CONF_API_KEY],
"client": config[DOMAIN][CLIENT_ID], "client": config[DOMAIN][CONF_CLIENT_ID],
} }
cppm = ClearPass(data) cppm = ClearPass(data)
if cppm.access_token is None: if cppm.access_token is None:

View File

@ -13,6 +13,8 @@ from homeassistant.components.http import HomeAssistantView
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM,
MASS_KILOGRAMS, MASS_KILOGRAMS,
MASS_MILLIGRAMS, MASS_MILLIGRAMS,
@ -32,8 +34,6 @@ _LOGGER = logging.getLogger(__name__)
ATTR_ACCESS_TOKEN = "access_token" ATTR_ACCESS_TOKEN = "access_token"
ATTR_REFRESH_TOKEN = "refresh_token" ATTR_REFRESH_TOKEN = "refresh_token"
ATTR_CLIENT_ID = "client_id"
ATTR_CLIENT_SECRET = "client_secret"
ATTR_LAST_SAVED_AT = "last_saved_at" ATTR_LAST_SAVED_AT = "last_saved_at"
CONF_MONITORED_RESOURCES = "monitored_resources" CONF_MONITORED_RESOURCES = "monitored_resources"
@ -47,7 +47,10 @@ FITBIT_DEFAULT_RESOURCES = ["activities/steps"]
SCAN_INTERVAL = datetime.timedelta(minutes=30) SCAN_INTERVAL = datetime.timedelta(minutes=30)
DEFAULT_CONFIG = {"client_id": "CLIENT_ID_HERE", "client_secret": "CLIENT_SECRET_HERE"} DEFAULT_CONFIG = {
CONF_CLIENT_ID: "CLIENT_ID_HERE",
CONF_CLIENT_SECRET: "CLIENT_SECRET_HERE",
}
FITBIT_RESOURCES_LIST = { FITBIT_RESOURCES_LIST = {
"activities/activityCalories": ["Activity Calories", "cal", "fire"], "activities/activityCalories": ["Activity Calories", "cal", "fire"],
@ -251,8 +254,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
expires_at = config_file.get(ATTR_LAST_SAVED_AT) expires_at = config_file.get(ATTR_LAST_SAVED_AT)
if None not in (access_token, refresh_token): if None not in (access_token, refresh_token):
authd_client = Fitbit( authd_client = Fitbit(
config_file.get(ATTR_CLIENT_ID), config_file.get(CONF_CLIENT_ID),
config_file.get(ATTR_CLIENT_SECRET), config_file.get(CONF_CLIENT_SECRET),
access_token=access_token, access_token=access_token,
refresh_token=refresh_token, refresh_token=refresh_token,
expires_at=expires_at, expires_at=expires_at,
@ -305,7 +308,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
else: else:
oauth = FitbitOauth2Client( oauth = FitbitOauth2Client(
config_file.get(ATTR_CLIENT_ID), config_file.get(ATTR_CLIENT_SECRET) config_file.get(CONF_CLIENT_ID), config_file.get(CONF_CLIENT_SECRET)
) )
redirect_uri = f"{get_url(hass)}{FITBIT_AUTH_CALLBACK_PATH}" redirect_uri = f"{get_url(hass)}{FITBIT_AUTH_CALLBACK_PATH}"
@ -388,8 +391,8 @@ class FitbitAuthCallbackView(HomeAssistantView):
config_contents = { config_contents = {
ATTR_ACCESS_TOKEN: result.get("access_token"), ATTR_ACCESS_TOKEN: result.get("access_token"),
ATTR_REFRESH_TOKEN: result.get("refresh_token"), ATTR_REFRESH_TOKEN: result.get("refresh_token"),
ATTR_CLIENT_ID: self.oauth.client_id, CONF_CLIENT_ID: self.oauth.client_id,
ATTR_CLIENT_SECRET: self.oauth.client_secret, CONF_CLIENT_SECRET: self.oauth.client_secret,
ATTR_LAST_SAVED_AT: int(time.time()), ATTR_LAST_SAVED_AT: int(time.time()),
} }
save_json(hass.config.path(FITBIT_CONFIG_FILE), config_contents) save_json(hass.config.path(FITBIT_CONFIG_FILE), config_contents)
@ -514,8 +517,8 @@ class FitbitSensor(Entity):
config_contents = { config_contents = {
ATTR_ACCESS_TOKEN: token.get("access_token"), ATTR_ACCESS_TOKEN: token.get("access_token"),
ATTR_REFRESH_TOKEN: token.get("refresh_token"), ATTR_REFRESH_TOKEN: token.get("refresh_token"),
ATTR_CLIENT_ID: self.client.client.client_id, CONF_CLIENT_ID: self.client.client.client_id,
ATTR_CLIENT_SECRET: self.client.client.client_secret, CONF_CLIENT_SECRET: self.client.client.client_secret,
ATTR_LAST_SAVED_AT: int(time.time()), ATTR_LAST_SAVED_AT: int(time.time()),
} }
save_json(self.config_path, config_contents) save_json(self.config_path, config_contents)

View File

@ -6,14 +6,17 @@ from ritassist import API
import voluptuous as vol import voluptuous as vol
from homeassistant.components.device_tracker import PLATFORM_SCHEMA from homeassistant.components.device_tracker import PLATFORM_SCHEMA
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_PASSWORD,
CONF_USERNAME,
)
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_utc_time_change from homeassistant.helpers.event import track_utc_time_change
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_INCLUDE = "include" CONF_INCLUDE = "include"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(

View File

@ -8,14 +8,17 @@ from requests import Session
from requests.exceptions import RequestException from requests.exceptions import RequestException
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_PASSWORD,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from .const import ( from .const import (
BASE_TOKEN_FILENAME, BASE_TOKEN_FILENAME,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DOMAIN, DOMAIN,
FLUME_AUTH, FLUME_AUTH,
FLUME_DEVICES, FLUME_DEVICES,

View File

@ -7,9 +7,14 @@ from requests.exceptions import RequestException
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries, core, exceptions from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_PASSWORD,
CONF_USERNAME,
)
from .const import BASE_TOKEN_FILENAME, CONF_CLIENT_ID, CONF_CLIENT_SECRET from .const import BASE_TOKEN_FILENAME
from .const import DOMAIN # pylint:disable=unused-import from .const import DOMAIN # pylint:disable=unused-import
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -5,8 +5,6 @@ PLATFORMS = ["sensor"]
DEFAULT_NAME = "Flume Sensor" DEFAULT_NAME = "Flume Sensor"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
FLUME_TYPE_SENSOR = 2 FLUME_TYPE_SENSOR = 2
FLUME_AUTH = "flume_auth" FLUME_AUTH = "flume_auth"

View File

@ -7,14 +7,18 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
)
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
from .const import ( from .const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DEFAULT_NAME, DEFAULT_NAME,
DOMAIN, DOMAIN,
FLUME_AUTH, FLUME_AUTH,

View File

@ -15,6 +15,7 @@ import voluptuous as vol
from voluptuous.error import Error as VoluptuousError from voluptuous.error import Error as VoluptuousError
import yaml import yaml
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import discovery from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import generate_entity_id from homeassistant.helpers.entity import generate_entity_id
@ -26,8 +27,6 @@ _LOGGER = logging.getLogger(__name__)
DOMAIN = "google" DOMAIN = "google"
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_TRACK_NEW = "track_new_calendar" CONF_TRACK_NEW = "track_new_calendar"
CONF_CAL_ID = "cal_id" CONF_CAL_ID = "cal_id"

View File

@ -4,14 +4,14 @@ import logging
from lmnotify import LaMetricManager from lmnotify import LaMetricManager
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
DOMAIN = "lametric" DOMAIN = "lametric"
LAMETRIC_DEVICES = "LAMETRIC_DEVICES" LAMETRIC_DEVICES = "LAMETRIC_DEVICES"
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(

View File

@ -12,6 +12,8 @@ from homeassistant import config_entries
from homeassistant.components.camera import ATTR_FILENAME, CAMERA_SERVICE_SCHEMA from homeassistant.components.camera import ATTR_FILENAME, CAMERA_SERVICE_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
ATTR_MODE, ATTR_MODE,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_SENSORS, CONF_SENSORS,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
@ -22,8 +24,6 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
from . import config_flow from . import config_flow
from .const import ( from .const import (
CONF_API_KEY, CONF_API_KEY,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_REDIRECT_URI, CONF_REDIRECT_URI,
DATA_LOGI, DATA_LOGI,
DEFAULT_CACHEDB, DEFAULT_CACHEDB,

View File

@ -9,17 +9,15 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.const import CONF_SENSORS, HTTP_BAD_REQUEST from homeassistant.const import (
from homeassistant.core import callback
from .const import (
CONF_API_KEY,
CONF_CLIENT_ID, CONF_CLIENT_ID,
CONF_CLIENT_SECRET, CONF_CLIENT_SECRET,
CONF_REDIRECT_URI, CONF_SENSORS,
DEFAULT_CACHEDB, HTTP_BAD_REQUEST,
DOMAIN,
) )
from homeassistant.core import callback
from .const import CONF_API_KEY, CONF_REDIRECT_URI, DEFAULT_CACHEDB, DOMAIN
_TIMEOUT = 15 # seconds _TIMEOUT = 15 # seconds

View File

@ -1,15 +1,14 @@
"""Constants in Logi Circle component.""" """Constants in Logi Circle component."""
from homeassistant.const import UNIT_PERCENTAGE from homeassistant.const import UNIT_PERCENTAGE
CONF_CLIENT_ID = "client_id" DOMAIN = "logi_circle"
CONF_CLIENT_SECRET = "client_secret" DATA_LOGI = DOMAIN
CONF_API_KEY = "api_key" CONF_API_KEY = "api_key"
CONF_REDIRECT_URI = "redirect_uri" CONF_REDIRECT_URI = "redirect_uri"
DEFAULT_CACHEDB = ".logi_cache.pickle" DEFAULT_CACHEDB = ".logi_cache.pickle"
DOMAIN = "logi_circle"
DATA_LOGI = DOMAIN
LED_MODE_KEY = "LED" LED_MODE_KEY = "LED"
RECORDING_MODE_KEY = "RECORDING_MODE" RECORDING_MODE_KEY = "RECORDING_MODE"

View File

@ -8,15 +8,13 @@ from lyft_rides.errors import APIError
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import TIME_MINUTES from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, TIME_MINUTES
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_END_LATITUDE = "end_latitude" CONF_END_LATITUDE = "end_latitude"
CONF_END_LONGITUDE = "end_longitude" CONF_END_LONGITUDE = "end_longitude"
CONF_PRODUCT_IDS = "product_ids" CONF_PRODUCT_IDS = "product_ids"

View File

@ -6,14 +6,12 @@ from mastodon.Mastodon import MastodonAPIError, MastodonUnauthorizedError
import voluptuous as vol import voluptuous as vol
from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService
from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_CLIENT_SECRET
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_BASE_URL = "base_url" CONF_BASE_URL = "base_url"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
DEFAULT_URL = "https://mastodon.social" DEFAULT_URL = "https://mastodon.social"

View File

@ -18,6 +18,7 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components import websocket_api from homeassistant.components import websocket_api
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID,
CONF_DEVICE, CONF_DEVICE,
CONF_NAME, CONF_NAME,
CONF_PASSWORD, CONF_PASSWORD,
@ -70,7 +71,6 @@ SERVICE_DUMP = "dump"
CONF_EMBEDDED = "embedded" CONF_EMBEDDED = "embedded"
CONF_CLIENT_ID = "client_id"
CONF_DISCOVERY_PREFIX = "discovery_prefix" CONF_DISCOVERY_PREFIX = "discovery_prefix"
CONF_KEEPALIVE = "keepalive" CONF_KEEPALIVE = "keepalive"
CONF_CERTIFICATE = "certificate" CONF_CERTIFICATE = "certificate"

View File

@ -10,6 +10,8 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import ( from homeassistant.const import (
CONF_BINARY_SENSORS, CONF_BINARY_SENSORS,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_FILENAME, CONF_FILENAME,
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_SENSORS, CONF_SENSORS,
@ -37,8 +39,6 @@ DATA_NEST_CONFIG = "nest_config"
SIGNAL_NEST_UPDATE = "nest_update" SIGNAL_NEST_UPDATE = "nest_update"
NEST_CONFIG_FILE = "nest.conf" NEST_CONFIG_FILE = "nest.conf"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
ATTR_ETA = "eta" ATTR_ETA = "eta"
ATTR_ETA_WINDOW = "eta_window" ATTR_ETA_WINDOW = "eta_window"

View File

@ -13,6 +13,7 @@ from homeassistant import config_entries
from homeassistant.components.http.view import HomeAssistantView from homeassistant.components.http.view import HomeAssistantView
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID,
CONF_HOST, CONF_HOST,
CONF_PORT, CONF_PORT,
CONF_SSL, CONF_SSL,
@ -29,7 +30,6 @@ from .const import ( # pylint: disable=unused-import
AUTH_CALLBACK_NAME, AUTH_CALLBACK_NAME,
AUTH_CALLBACK_PATH, AUTH_CALLBACK_PATH,
AUTOMATIC_SETUP_STRING, AUTOMATIC_SETUP_STRING,
CONF_CLIENT_IDENTIFIER,
CONF_IGNORE_NEW_SHARED_USERS, CONF_IGNORE_NEW_SHARED_USERS,
CONF_IGNORE_PLEX_WEB_CLIENTS, CONF_IGNORE_PLEX_WEB_CLIENTS,
CONF_MONITORED_USERS, CONF_MONITORED_USERS,
@ -227,7 +227,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
entry_config = {CONF_URL: url} entry_config = {CONF_URL: url}
if self.client_id: if self.client_id:
entry_config[CONF_CLIENT_IDENTIFIER] = self.client_id entry_config[CONF_CLIENT_ID] = self.client_id
if token: if token:
entry_config[CONF_TOKEN] = token entry_config[CONF_TOKEN] = token
if url.startswith("https"): if url.startswith("https"):

View File

@ -24,7 +24,6 @@ PLEX_UPDATE_MEDIA_PLAYER_SIGNAL = "plex_update_mp_signal.{}"
PLEX_UPDATE_PLATFORMS_SIGNAL = "plex_update_platforms_signal.{}" PLEX_UPDATE_PLATFORMS_SIGNAL = "plex_update_platforms_signal.{}"
PLEX_UPDATE_SENSOR_SIGNAL = "plex_update_sensor_signal.{}" PLEX_UPDATE_SENSOR_SIGNAL = "plex_update_sensor_signal.{}"
CONF_CLIENT_IDENTIFIER = "client_id"
CONF_SERVER = "server" CONF_SERVER = "server"
CONF_SERVER_IDENTIFIER = "server_id" CONF_SERVER_IDENTIFIER = "server_id"
CONF_USE_EPISODE_ART = "use_episode_art" CONF_USE_EPISODE_ART = "use_episode_art"

View File

@ -17,13 +17,12 @@ from homeassistant.components.media_player.const import (
MEDIA_TYPE_PLAYLIST, MEDIA_TYPE_PLAYLIST,
MEDIA_TYPE_VIDEO, MEDIA_TYPE_VIDEO,
) )
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL from homeassistant.const import CONF_CLIENT_ID, CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import ( from .const import (
CONF_CLIENT_IDENTIFIER,
CONF_IGNORE_NEW_SHARED_USERS, CONF_IGNORE_NEW_SHARED_USERS,
CONF_IGNORE_PLEX_WEB_CLIENTS, CONF_IGNORE_PLEX_WEB_CLIENTS,
CONF_MONITORED_USERS, CONF_MONITORED_USERS,
@ -81,8 +80,8 @@ class PlexServer:
).async_call ).async_call
# Header conditionally added as it is not available in config entry v1 # Header conditionally added as it is not available in config entry v1
if CONF_CLIENT_IDENTIFIER in server_config: if CONF_CLIENT_ID in server_config:
plexapi.X_PLEX_IDENTIFIER = server_config[CONF_CLIENT_IDENTIFIER] plexapi.X_PLEX_IDENTIFIER = server_config[CONF_CLIENT_ID]
plexapi.myplex.BASE_HEADERS = plexapi.reset_base_headers() plexapi.myplex.BASE_HEADERS = plexapi.reset_base_headers()
plexapi.server.BASE_HEADERS = plexapi.reset_base_headers() plexapi.server.BASE_HEADERS = plexapi.reset_base_headers()

View File

@ -7,7 +7,12 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_TOKEN, CONF_WEBHOOK_ID from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_TOKEN,
CONF_WEBHOOK_ID,
)
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
@ -31,9 +36,6 @@ from .const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
DATA_CONFIG_ENTRY_LOCK = "point_config_entry_lock" DATA_CONFIG_ENTRY_LOCK = "point_config_entry_lock"
CONFIG_ENTRY_IS_SETUP = "point_config_entry_is_setup" CONFIG_ENTRY_IS_SETUP = "point_config_entry_is_setup"
@ -82,7 +84,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
# Force token update. # Force token update.
entry.data[CONF_TOKEN]["expires_in"] = -1 entry.data[CONF_TOKEN]["expires_in"] = -1
session = PointSession( session = PointSession(
entry.data["refresh_args"]["client_id"], entry.data["refresh_args"][CONF_CLIENT_ID],
token=entry.data[CONF_TOKEN], token=entry.data[CONF_TOKEN],
auto_refresh_kwargs=entry.data["refresh_args"], auto_refresh_kwargs=entry.data["refresh_args"],
token_saver=token_saver, token_saver=token_saver,

View File

@ -9,9 +9,10 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.core import callback from homeassistant.core import callback
from .const import CLIENT_ID, CLIENT_SECRET, DOMAIN from .const import DOMAIN
AUTH_CALLBACK_PATH = "/api/minut" AUTH_CALLBACK_PATH = "/api/minut"
AUTH_CALLBACK_NAME = "api:minut" AUTH_CALLBACK_NAME = "api:minut"
@ -34,8 +35,8 @@ def register_flow_implementation(hass, domain, client_id, client_secret):
hass.data[DATA_FLOW_IMPL] = OrderedDict() hass.data[DATA_FLOW_IMPL] = OrderedDict()
hass.data[DATA_FLOW_IMPL][domain] = { hass.data[DATA_FLOW_IMPL][domain] = {
CLIENT_ID: client_id, CONF_CLIENT_ID: client_id,
CLIENT_SECRET: client_secret, CONF_CLIENT_SECRET: client_secret,
} }
@ -112,8 +113,8 @@ class PointFlowHandler(config_entries.ConfigFlow):
"""Create Minut Point session and get authorization url.""" """Create Minut Point session and get authorization url."""
flow = self.hass.data[DATA_FLOW_IMPL][self.flow_impl] flow = self.hass.data[DATA_FLOW_IMPL][self.flow_impl]
client_id = flow[CLIENT_ID] client_id = flow[CONF_CLIENT_ID]
client_secret = flow[CLIENT_SECRET] client_secret = flow[CONF_CLIENT_SECRET]
point_session = PointSession(client_id, client_secret=client_secret) point_session = PointSession(client_id, client_secret=client_secret)
self.hass.http.register_view(MinutAuthCallbackView()) self.hass.http.register_view(MinutAuthCallbackView())
@ -140,8 +141,8 @@ class PointFlowHandler(config_entries.ConfigFlow):
"""Create point session and entries.""" """Create point session and entries."""
flow = self.hass.data[DATA_FLOW_IMPL][DOMAIN] flow = self.hass.data[DATA_FLOW_IMPL][DOMAIN]
client_id = flow[CLIENT_ID] client_id = flow[CONF_CLIENT_ID]
client_secret = flow[CLIENT_SECRET] client_secret = flow[CONF_CLIENT_SECRET]
point_session = PointSession(client_id, client_secret=client_secret) point_session = PointSession(client_id, client_secret=client_secret)
token = await self.hass.async_add_executor_job( token = await self.hass.async_add_executor_job(
point_session.get_access_token, code point_session.get_access_token, code
@ -159,8 +160,8 @@ class PointFlowHandler(config_entries.ConfigFlow):
data={ data={
"token": token, "token": token,
"refresh_args": { "refresh_args": {
"client_id": client_id, CONF_CLIENT_ID: client_id,
"client_secret": client_secret, CONF_CLIENT_SECRET: client_secret,
}, },
}, },
) )

View File

@ -2,9 +2,6 @@
from datetime import timedelta from datetime import timedelta
DOMAIN = "point" DOMAIN = "point"
CLIENT_ID = "client_id"
CLIENT_SECRET = "client_secret"
SCAN_INTERVAL = timedelta(minutes=1) SCAN_INTERVAL = timedelta(minutes=1)

View File

@ -6,14 +6,18 @@ import praw
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_MAXIMUM, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_MAXIMUM,
CONF_PASSWORD,
CONF_USERNAME,
)
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_SORT_BY = "sort_by" CONF_SORT_BY = "sort_by"
CONF_SUBREDDITS = "subreddits" CONF_SUBREDDITS = "subreddits"

View File

@ -7,7 +7,13 @@ from requests.exceptions import RequestException
import smappy import smappy
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_HOST,
CONF_PASSWORD,
CONF_USERNAME,
)
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.discovery import load_platform
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -17,8 +23,6 @@ _LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = "Smappee" DEFAULT_NAME = "Smappee"
DEFAULT_HOST_PASSWORD = "admin" DEFAULT_HOST_PASSWORD = "admin"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_HOST_PASSWORD = "host_password" CONF_HOST_PASSWORD = "host_password"
DOMAIN = "smappee" DOMAIN = "smappee"

View File

@ -9,7 +9,12 @@ from pysmartapp.event import EVENT_TYPE_DEVICE
from pysmartthings import Attribute, Capability, SmartThings from pysmartthings import Attribute, Capability, SmartThings
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ACCESS_TOKEN, HTTP_FORBIDDEN from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
HTTP_FORBIDDEN,
)
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (
@ -25,8 +30,6 @@ from .const import (
CONF_APP_ID, CONF_APP_ID,
CONF_INSTALLED_APP_ID, CONF_INSTALLED_APP_ID,
CONF_LOCATION_ID, CONF_LOCATION_ID,
CONF_OAUTH_CLIENT_ID,
CONF_OAUTH_CLIENT_SECRET,
CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN,
DATA_BROKERS, DATA_BROKERS,
DATA_MANAGER, DATA_MANAGER,
@ -115,8 +118,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
# Get SmartApp token to sync subscriptions # Get SmartApp token to sync subscriptions
token = await api.generate_tokens( token = await api.generate_tokens(
entry.data[CONF_OAUTH_CLIENT_ID], entry.data[CONF_CLIENT_ID],
entry.data[CONF_OAUTH_CLIENT_SECRET], entry.data[CONF_CLIENT_SECRET],
entry.data[CONF_REFRESH_TOKEN], entry.data[CONF_REFRESH_TOKEN],
) )
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
@ -312,8 +315,7 @@ class DeviceBroker:
async def regenerate_refresh_token(now): async def regenerate_refresh_token(now):
"""Generate a new refresh token and update the config entry.""" """Generate a new refresh token and update the config entry."""
await self._token.refresh( await self._token.refresh(
self._entry.data[CONF_OAUTH_CLIENT_ID], self._entry.data[CONF_CLIENT_ID], self._entry.data[CONF_CLIENT_SECRET],
self._entry.data[CONF_OAUTH_CLIENT_SECRET],
) )
self._hass.config_entries.async_update_entry( self._hass.config_entries.async_update_entry(
self._entry, self._entry,

View File

@ -7,7 +7,13 @@ from pysmartthings.installedapp import format_install_url
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_ACCESS_TOKEN, HTTP_FORBIDDEN, HTTP_UNAUTHORIZED from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
HTTP_FORBIDDEN,
HTTP_UNAUTHORIZED,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
# pylint: disable=unused-import # pylint: disable=unused-import
@ -17,8 +23,6 @@ from .const import (
CONF_APP_ID, CONF_APP_ID,
CONF_INSTALLED_APP_ID, CONF_INSTALLED_APP_ID,
CONF_LOCATION_ID, CONF_LOCATION_ID,
CONF_OAUTH_CLIENT_ID,
CONF_OAUTH_CLIENT_SECRET,
CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN,
DOMAIN, DOMAIN,
VAL_UID_MATCHER, VAL_UID_MATCHER,
@ -112,8 +116,8 @@ class SmartThingsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
None, None,
) )
if existing: if existing:
self.oauth_client_id = existing.data[CONF_OAUTH_CLIENT_ID] self.oauth_client_id = existing.data[CONF_CLIENT_ID]
self.oauth_client_secret = existing.data[CONF_OAUTH_CLIENT_SECRET] self.oauth_client_secret = existing.data[CONF_CLIENT_SECRET]
else: else:
# Get oauth client id/secret by regenerating it # Get oauth client id/secret by regenerating it
app_oauth = AppOAuth(app.app_id) app_oauth = AppOAuth(app.app_id)
@ -227,8 +231,8 @@ class SmartThingsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
data = { data = {
CONF_ACCESS_TOKEN: self.access_token, CONF_ACCESS_TOKEN: self.access_token,
CONF_REFRESH_TOKEN: self.refresh_token, CONF_REFRESH_TOKEN: self.refresh_token,
CONF_OAUTH_CLIENT_ID: self.oauth_client_id, CONF_CLIENT_ID: self.oauth_client_id,
CONF_OAUTH_CLIENT_SECRET: self.oauth_client_secret, CONF_CLIENT_SECRET: self.oauth_client_secret,
CONF_LOCATION_ID: self.location_id, CONF_LOCATION_ID: self.location_id,
CONF_APP_ID: self.app_id, CONF_APP_ID: self.app_id,
CONF_INSTALLED_APP_ID: self.installed_app_id, CONF_INSTALLED_APP_ID: self.installed_app_id,

View File

@ -2,26 +2,31 @@
from datetime import timedelta from datetime import timedelta
import re import re
DOMAIN = "smartthings"
APP_OAUTH_CLIENT_NAME = "Home Assistant" APP_OAUTH_CLIENT_NAME = "Home Assistant"
APP_OAUTH_SCOPES = ["r:devices:*"] APP_OAUTH_SCOPES = ["r:devices:*"]
APP_NAME_PREFIX = "homeassistant." APP_NAME_PREFIX = "homeassistant."
CONF_APP_ID = "app_id" CONF_APP_ID = "app_id"
CONF_CLOUDHOOK_URL = "cloudhook_url" CONF_CLOUDHOOK_URL = "cloudhook_url"
CONF_INSTALLED_APP_ID = "installed_app_id" CONF_INSTALLED_APP_ID = "installed_app_id"
CONF_INSTANCE_ID = "instance_id" CONF_INSTANCE_ID = "instance_id"
CONF_LOCATION_ID = "location_id" CONF_LOCATION_ID = "location_id"
CONF_OAUTH_CLIENT_ID = "client_id"
CONF_OAUTH_CLIENT_SECRET = "client_secret"
CONF_REFRESH_TOKEN = "refresh_token" CONF_REFRESH_TOKEN = "refresh_token"
DATA_MANAGER = "manager" DATA_MANAGER = "manager"
DATA_BROKERS = "brokers" DATA_BROKERS = "brokers"
DOMAIN = "smartthings"
EVENT_BUTTON = "smartthings.button" EVENT_BUTTON = "smartthings.button"
SIGNAL_SMARTTHINGS_UPDATE = "smartthings_update" SIGNAL_SMARTTHINGS_UPDATE = "smartthings_update"
SIGNAL_SMARTAPP_PREFIX = "smartthings_smartap_" SIGNAL_SMARTAPP_PREFIX = "smartthings_smartap_"
SETTINGS_INSTANCE_ID = "hassInstanceId" SETTINGS_INSTANCE_ID = "hassInstanceId"
STORAGE_KEY = DOMAIN STORAGE_KEY = DOMAIN
STORAGE_VERSION = 1 STORAGE_VERSION = 1
# Ordered 'specific to least-specific platform' in order for capabilities # Ordered 'specific to least-specific platform' in order for capabilities
# to be drawn-down and represented by the most appropriate platform. # to be drawn-down and represented by the most appropriate platform.
SUPPORTED_PLATFORMS = [ SUPPORTED_PLATFORMS = [
@ -35,6 +40,8 @@ SUPPORTED_PLATFORMS = [
"sensor", "sensor",
"scene", "scene",
] ]
TOKEN_REFRESH_INTERVAL = timedelta(days=14) TOKEN_REFRESH_INTERVAL = timedelta(days=14)
VAL_UID = "^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$" VAL_UID = "^(?:([0-9a-fA-F]{32})|([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}))$"
VAL_UID_MATCHER = re.compile(VAL_UID) VAL_UID_MATCHER = re.compile(VAL_UID)

View File

@ -9,6 +9,7 @@ import voluptuous as vol
from homeassistant.components.somfy import config_flow from homeassistant.components.somfy import config_flow
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import ( from homeassistant.helpers import (
config_entry_oauth2_flow, config_entry_oauth2_flow,
config_validation as cv, config_validation as cv,
@ -19,6 +20,7 @@ from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import Throttle from homeassistant.util import Throttle
from . import api from . import api
from .const import DOMAIN
API = "api" API = "api"
@ -28,10 +30,7 @@ _LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = timedelta(seconds=30) SCAN_INTERVAL = timedelta(seconds=30)
DOMAIN = "somfy"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_OPTIMISTIC = "optimistic" CONF_OPTIMISTIC = "optimistic"
SOMFY_AUTH_CALLBACK_PATH = "/auth/somfy/callback" SOMFY_AUTH_CALLBACK_PATH = "/auth/somfy/callback"

View File

@ -6,7 +6,7 @@ import voluptuous as vol
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.components.spotify import config_flow from homeassistant.components.spotify import config_flow
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_CREDENTIALS from homeassistant.const import ATTR_CREDENTIALS, CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
@ -16,14 +16,7 @@ from homeassistant.helpers.config_entry_oauth2_flow import (
) )
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from .const import ( from .const import DATA_SPOTIFY_CLIENT, DATA_SPOTIFY_ME, DATA_SPOTIFY_SESSION, DOMAIN
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DATA_SPOTIFY_CLIENT,
DATA_SPOTIFY_ME,
DATA_SPOTIFY_SESSION,
DOMAIN,
)
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(
{ {

View File

@ -2,9 +2,6 @@
DOMAIN = "spotify" DOMAIN = "spotify"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
DATA_SPOTIFY_CLIENT = "spotify_client" DATA_SPOTIFY_CLIENT = "spotify_client"
DATA_SPOTIFY_ME = "spotify_me" DATA_SPOTIFY_ME = "spotify_me"
DATA_SPOTIFY_SESSION = "spotify_session" DATA_SPOTIFY_SESSION = "spotify_session"

View File

@ -6,7 +6,13 @@ from typing import Any, Dict
from toonapilib import Toon from toonapilib import Toon
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
@ -16,8 +22,6 @@ from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from . import config_flow # noqa: F401 from . import config_flow # noqa: F401
from .const import ( from .const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_DISPLAY, CONF_DISPLAY,
CONF_TENANT, CONF_TENANT,
DATA_TOON, DATA_TOON,

View File

@ -13,17 +13,15 @@ from toonapilib.toonapilibexceptions import (
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
from homeassistant.core import callback
from .const import (
CONF_CLIENT_ID, CONF_CLIENT_ID,
CONF_CLIENT_SECRET, CONF_CLIENT_SECRET,
CONF_DISPLAY, CONF_PASSWORD,
CONF_TENANT, CONF_USERNAME,
DATA_TOON_CONFIG,
DOMAIN,
) )
from homeassistant.core import callback
from .const import CONF_DISPLAY, CONF_TENANT, DATA_TOON_CONFIG, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -94,10 +92,10 @@ class ToonFlowHandler(config_entries.ConfigFlow):
displays = toon.display_names displays = toon.display_names
except InvalidConsumerKey: except InvalidConsumerKey:
return self.async_abort(reason="client_id") return self.async_abort(reason=CONF_CLIENT_ID)
except InvalidConsumerSecret: except InvalidConsumerSecret:
return self.async_abort(reason="client_secret") return self.async_abort(reason=CONF_CLIENT_SECRET)
except InvalidCredentials: except InvalidCredentials:
return await self._show_authenticaticate_form({"base": "credentials"}) return await self._show_authenticaticate_form({"base": "credentials"})

View File

@ -8,8 +8,6 @@ DATA_TOON_CLIENT = "toon_client"
DATA_TOON_CONFIG = "toon_config" DATA_TOON_CONFIG = "toon_config"
DATA_TOON_UPDATED = "toon_updated" DATA_TOON_UPDATED = "toon_updated"
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_DISPLAY = "display" CONF_DISPLAY = "display"
CONF_TENANT = "tenant" CONF_TENANT = "tenant"

View File

@ -6,7 +6,7 @@ from twitch import TwitchClient
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_TOKEN from homeassistant.const import CONF_CLIENT_ID, CONF_TOKEN
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -23,7 +23,6 @@ ATTR_FOLLOWING = "followers"
ATTR_VIEWS = "views" ATTR_VIEWS = "views"
CONF_CHANNELS = "channels" CONF_CHANNELS = "channels"
CONF_CLIENT_ID = "client_id"
ICON = "mdi:twitch" ICON = "mdi:twitch"

View File

@ -14,6 +14,8 @@ from homeassistant.components.http import HomeAssistantView
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
ATTR_NAME, ATTR_NAME,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_EMAIL, CONF_EMAIL,
CONF_PASSWORD, CONF_PASSWORD,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_START,
@ -38,8 +40,6 @@ DOMAIN = "wink"
SUBSCRIPTION_HANDLER = None SUBSCRIPTION_HANDLER = None
CONF_CLIENT_ID = "client_id"
CONF_CLIENT_SECRET = "client_secret"
CONF_USER_AGENT = "user_agent" CONF_USER_AGENT = "user_agent"
CONF_OAUTH = "oauth" CONF_OAUTH = "oauth"
CONF_LOCAL_CONTROL = "local_control" CONF_LOCAL_CONTROL = "local_control"
@ -47,8 +47,6 @@ CONF_MISSING_OAUTH_MSG = "Missing oauth2 credentials."
ATTR_ACCESS_TOKEN = "access_token" ATTR_ACCESS_TOKEN = "access_token"
ATTR_REFRESH_TOKEN = "refresh_token" ATTR_REFRESH_TOKEN = "refresh_token"
ATTR_CLIENT_ID = "client_id"
ATTR_CLIENT_SECRET = "client_secret"
ATTR_PAIRING_MODE = "pairing_mode" ATTR_PAIRING_MODE = "pairing_mode"
ATTR_KIDDE_RADIO_CODE = "kidde_radio_code" ATTR_KIDDE_RADIO_CODE = "kidde_radio_code"
ATTR_HUB_NAME = "hub_name" ATTR_HUB_NAME = "hub_name"
@ -58,7 +56,10 @@ WINK_AUTH_START = "/auth/wink"
WINK_CONFIG_FILE = ".wink.conf" WINK_CONFIG_FILE = ".wink.conf"
USER_AGENT = f"Manufacturer/Home-Assistant{__version__} python/3 Wink/3" USER_AGENT = f"Manufacturer/Home-Assistant{__version__} python/3 Wink/3"
DEFAULT_CONFIG = {"client_id": "CLIENT_ID_HERE", "client_secret": "CLIENT_SECRET_HERE"} DEFAULT_CONFIG = {
CONF_CLIENT_ID: "CLIENT_ID_HERE",
CONF_CLIENT_SECRET: "CLIENT_SECRET_HERE",
}
SERVICE_ADD_NEW_DEVICES = "pull_newly_added_devices_from_wink" SERVICE_ADD_NEW_DEVICES = "pull_newly_added_devices_from_wink"
SERVICE_REFRESH_STATES = "refresh_state_from_wink" SERVICE_REFRESH_STATES = "refresh_state_from_wink"
@ -219,12 +220,12 @@ def _request_app_setup(hass, config):
setup(hass, config) setup(hass, config)
return return
client_id = callback_data.get("client_id").strip() client_id = callback_data.get(CONF_CLIENT_ID).strip()
client_secret = callback_data.get("client_secret").strip() client_secret = callback_data.get(CONF_CLIENT_SECRET).strip()
if None not in (client_id, client_secret): if None not in (client_id, client_secret):
save_json( save_json(
_config_path, _config_path,
{ATTR_CLIENT_ID: client_id, ATTR_CLIENT_SECRET: client_secret}, {CONF_CLIENT_ID: client_id, CONF_CLIENT_SECRET: client_secret},
) )
setup(hass, config) setup(hass, config)
return return
@ -249,8 +250,8 @@ def _request_app_setup(hass, config):
submit_caption="submit", submit_caption="submit",
description_image="/static/images/config_wink.png", description_image="/static/images/config_wink.png",
fields=[ fields=[
{"id": "client_id", "name": "Client ID", "type": "string"}, {"id": CONF_CLIENT_ID, "name": "Client ID", "type": "string"},
{"id": "client_secret", "name": "Client secret", "type": "string"}, {"id": CONF_CLIENT_SECRET, "name": "Client secret", "type": "string"},
], ],
) )
@ -293,8 +294,8 @@ def setup(hass, config):
} }
if config.get(DOMAIN) is not None: if config.get(DOMAIN) is not None:
client_id = config[DOMAIN].get(ATTR_CLIENT_ID) client_id = config[DOMAIN].get(CONF_CLIENT_ID)
client_secret = config[DOMAIN].get(ATTR_CLIENT_SECRET) client_secret = config[DOMAIN].get(CONF_CLIENT_SECRET)
email = config[DOMAIN].get(CONF_EMAIL) email = config[DOMAIN].get(CONF_EMAIL)
password = config[DOMAIN].get(CONF_PASSWORD) password = config[DOMAIN].get(CONF_PASSWORD)
local_control = config[DOMAIN].get(CONF_LOCAL_CONTROL) local_control = config[DOMAIN].get(CONF_LOCAL_CONTROL)
@ -309,8 +310,8 @@ def setup(hass, config):
_LOGGER.info("Using legacy OAuth authentication") _LOGGER.info("Using legacy OAuth authentication")
if not local_control: if not local_control:
pywink.disable_local_control() pywink.disable_local_control()
hass.data[DOMAIN]["oauth"]["client_id"] = client_id hass.data[DOMAIN]["oauth"][CONF_CLIENT_ID] = client_id
hass.data[DOMAIN]["oauth"]["client_secret"] = client_secret hass.data[DOMAIN]["oauth"][CONF_CLIENT_SECRET] = client_secret
hass.data[DOMAIN]["oauth"]["email"] = email hass.data[DOMAIN]["oauth"]["email"] = email
hass.data[DOMAIN]["oauth"]["password"] = password hass.data[DOMAIN]["oauth"]["password"] = password
pywink.legacy_set_wink_credentials(email, password, client_id, client_secret) pywink.legacy_set_wink_credentials(email, password, client_id, client_secret)
@ -341,8 +342,8 @@ def setup(hass, config):
# This will be called after authorizing Home-Assistant # This will be called after authorizing Home-Assistant
if None not in (access_token, refresh_token): if None not in (access_token, refresh_token):
pywink.set_wink_credentials( pywink.set_wink_credentials(
config_file.get(ATTR_CLIENT_ID), config_file.get(CONF_CLIENT_ID),
config_file.get(ATTR_CLIENT_SECRET), config_file.get(CONF_CLIENT_SECRET),
access_token=access_token, access_token=access_token,
refresh_token=refresh_token, refresh_token=refresh_token,
) )
@ -353,7 +354,7 @@ def setup(hass, config):
redirect_uri = f"{get_url(hass)}{WINK_AUTH_CALLBACK_PATH}" redirect_uri = f"{get_url(hass)}{WINK_AUTH_CALLBACK_PATH}"
wink_auth_start_url = pywink.get_authorization_url( wink_auth_start_url = pywink.get_authorization_url(
config_file.get(ATTR_CLIENT_ID), redirect_uri config_file.get(CONF_CLIENT_ID), redirect_uri
) )
hass.http.register_redirect(WINK_AUTH_START, wink_auth_start_url) hass.http.register_redirect(WINK_AUTH_START, wink_auth_start_url)
hass.http.register_view( hass.http.register_view(
@ -698,14 +699,14 @@ class WinkAuthCallbackView(HomeAssistantView):
if data.get("code") is not None: if data.get("code") is not None:
response = self.request_token( response = self.request_token(
data.get("code"), self.config_file["client_secret"] data.get("code"), self.config_file[CONF_CLIENT_SECRET]
) )
config_contents = { config_contents = {
ATTR_ACCESS_TOKEN: response["access_token"], ATTR_ACCESS_TOKEN: response["access_token"],
ATTR_REFRESH_TOKEN: response["refresh_token"], ATTR_REFRESH_TOKEN: response["refresh_token"],
ATTR_CLIENT_ID: self.config_file["client_id"], CONF_CLIENT_ID: self.config_file[CONF_CLIENT_ID],
ATTR_CLIENT_SECRET: self.config_file["client_secret"], CONF_CLIENT_SECRET: self.config_file[CONF_CLIENT_SECRET],
} }
save_json(hass.config.path(WINK_CONFIG_FILE), config_contents) save_json(hass.config.path(WINK_CONFIG_FILE), config_contents)

View File

@ -7,23 +7,21 @@ import voluptuous as vol
from withings_api import WithingsAuth from withings_api import WithingsAuth
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
from homeassistant.helpers.typing import ConfigType, HomeAssistantType from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from . import config_flow, const from . import config_flow
from .common import _LOGGER, NotAuthenticatedError, get_data_manager from .common import _LOGGER, NotAuthenticatedError, get_data_manager
from .const import CONF_PROFILES, CONFIG, CREDENTIALS, DOMAIN
DOMAIN = const.DOMAIN
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = vol.Schema(
{ {
DOMAIN: vol.Schema( DOMAIN: vol.Schema(
{ {
vol.Required(const.CLIENT_ID): vol.All(cv.string, vol.Length(min=1)), vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(min=1)),
vol.Required(const.CLIENT_SECRET): vol.All( vol.Required(CONF_CLIENT_SECRET): vol.All(cv.string, vol.Length(min=1)),
cv.string, vol.Length(min=1) vol.Required(CONF_PROFILES): vol.All(
),
vol.Required(const.PROFILES): vol.All(
cv.ensure_list, cv.ensure_list,
vol.Unique(), vol.Unique(),
vol.Length(min=1), vol.Length(min=1),
@ -42,15 +40,15 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
if not conf: if not conf:
return True return True
hass.data[DOMAIN] = {const.CONFIG: conf} hass.data[DOMAIN] = {CONFIG: conf}
config_flow.WithingsFlowHandler.async_register_implementation( config_flow.WithingsFlowHandler.async_register_implementation(
hass, hass,
config_entry_oauth2_flow.LocalOAuth2Implementation( config_entry_oauth2_flow.LocalOAuth2Implementation(
hass, hass,
const.DOMAIN, DOMAIN,
conf[const.CLIENT_ID], conf[CONF_CLIENT_ID],
conf[const.CLIENT_SECRET], conf[CONF_CLIENT_SECRET],
f"{WithingsAuth.URL}/oauth2_user/authorize2", f"{WithingsAuth.URL}/oauth2_user/authorize2",
f"{WithingsAuth.URL}/oauth2/token", f"{WithingsAuth.URL}/oauth2/token",
), ),
@ -65,12 +63,12 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
if "auth_implementation" not in entry.data: if "auth_implementation" not in entry.data:
_LOGGER.debug("Upgrading existing config entry") _LOGGER.debug("Upgrading existing config entry")
data = entry.data data = entry.data
creds = data.get(const.CREDENTIALS, {}) creds = data.get(CREDENTIALS, {})
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
entry, entry,
data={ data={
"auth_implementation": const.DOMAIN, "auth_implementation": DOMAIN,
"implementation": const.DOMAIN, "implementation": DOMAIN,
"profile": data.get("profile"), "profile": data.get("profile"),
"token": { "token": {
"access_token": creds.get("access_token"), "access_token": creds.get("access_token"),

View File

@ -51,7 +51,7 @@ class WithingsFlowHandler(config_entry_oauth2_flow.AbstractOAuth2FlowHandler):
self._current_data = None self._current_data = None
return await self.async_step_finish(new_data) return await self.async_step_finish(new_data)
profiles = self.hass.data[const.DOMAIN][const.CONFIG][const.PROFILES] profiles = self.hass.data[const.DOMAIN][const.CONFIG][const.CONF_PROFILES]
return self.async_show_form( return self.async_show_form(
step_id="profile", step_id="profile",
data_schema=vol.Schema({vol.Required(const.PROFILE): vol.In(profiles)}), data_schema=vol.Schema({vol.Required(const.PROFILE): vol.In(profiles)}),

View File

@ -1,19 +1,19 @@
"""Constants used by the Withings component.""" """Constants used by the Withings component."""
import homeassistant.const as const import homeassistant.const as const
DOMAIN = "withings"
CONF_PROFILES = "profiles"
DATA_MANAGER = "data_manager" DATA_MANAGER = "data_manager"
BASE_URL = "base_url" BASE_URL = "base_url"
CLIENT_ID = "client_id"
CLIENT_SECRET = "client_secret"
CODE = "code" CODE = "code"
CONFIG = "config" CONFIG = "config"
CREDENTIALS = "credentials" CREDENTIALS = "credentials"
DOMAIN = "withings"
LOG_NAMESPACE = "homeassistant.components.withings" LOG_NAMESPACE = "homeassistant.components.withings"
MEASURES = "measures" MEASURES = "measures"
PROFILE = "profile" PROFILE = "profile"
PROFILES = "profiles"
AUTH_CALLBACK_PATH = "/api/withings/authorize" AUTH_CALLBACK_PATH = "/api/withings/authorize"
AUTH_CALLBACK_NAME = "withings:authorize" AUTH_CALLBACK_NAME = "withings:authorize"

View File

@ -4,13 +4,13 @@ import logging
import voluptuous as vol import voluptuous as vol
from wunderpy2 import WunderApi from wunderpy2 import WunderApi
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_NAME from homeassistant.const import CONF_ACCESS_TOKEN, CONF_CLIENT_ID, CONF_NAME
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DOMAIN = "wunderlist" DOMAIN = "wunderlist"
CONF_CLIENT_ID = "client_id"
CONF_LIST_NAME = "list_name" CONF_LIST_NAME = "list_name"
CONF_STARRED = "starred" CONF_STARRED = "starred"

View File

@ -1,5 +1,6 @@
"""Test Alexa auth endpoints.""" """Test Alexa auth endpoints."""
from homeassistant.components.alexa.auth import Auth from homeassistant.components.alexa.auth import Auth
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from . import TEST_TOKEN_URL from . import TEST_TOKEN_URL
@ -53,13 +54,13 @@ async def test_auth_get_access_token_expired(hass, aioclient_mock):
assert auth_call_json["grant_type"] == "authorization_code" assert auth_call_json["grant_type"] == "authorization_code"
assert auth_call_json["code"] == accept_grant_code assert auth_call_json["code"] == accept_grant_code
assert auth_call_json["client_id"] == client_id assert auth_call_json[CONF_CLIENT_ID] == client_id
assert auth_call_json["client_secret"] == client_secret assert auth_call_json[CONF_CLIENT_SECRET] == client_secret
assert token_call_json["grant_type"] == "refresh_token" assert token_call_json["grant_type"] == "refresh_token"
assert token_call_json["refresh_token"] == refresh_token assert token_call_json["refresh_token"] == refresh_token
assert token_call_json["client_id"] == client_id assert token_call_json[CONF_CLIENT_ID] == client_id
assert token_call_json["client_secret"] == client_secret assert token_call_json[CONF_CLIENT_SECRET] == client_secret
async def test_auth_get_access_token_not_expired(hass, aioclient_mock): async def test_auth_get_access_token_not_expired(hass, aioclient_mock):
@ -86,5 +87,5 @@ async def test_auth_get_access_token_not_expired(hass, aioclient_mock):
assert auth_call_json["grant_type"] == "authorization_code" assert auth_call_json["grant_type"] == "authorization_code"
assert auth_call_json["code"] == accept_grant_code assert auth_call_json["code"] == accept_grant_code
assert auth_call_json["client_id"] == client_id assert auth_call_json[CONF_CLIENT_ID] == client_id
assert auth_call_json["client_secret"] == client_secret assert auth_call_json[CONF_CLIENT_SECRET] == client_secret

View File

@ -4,6 +4,7 @@ import asyncio
from homeassistant import config_entries, data_entry_flow, setup from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.components.almond import config_flow from homeassistant.components.almond import config_flow
from homeassistant.components.almond.const import DOMAIN from homeassistant.components.almond.const import DOMAIN
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.async_mock import patch from tests.async_mock import patch
@ -17,9 +18,7 @@ async def test_import(hass):
"""Test that we can import a config entry.""" """Test that we can import a config entry."""
with patch("pyalmond.WebAlmondAPI.async_list_apps"): with patch("pyalmond.WebAlmondAPI.async_list_apps"):
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass, DOMAIN, {DOMAIN: {"type": "local", "host": "http://localhost:3000"}},
"almond",
{"almond": {"type": "local", "host": "http://localhost:3000"}},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -35,9 +34,7 @@ async def test_import_cannot_connect(hass):
"pyalmond.WebAlmondAPI.async_list_apps", side_effect=asyncio.TimeoutError "pyalmond.WebAlmondAPI.async_list_apps", side_effect=asyncio.TimeoutError
): ):
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass, DOMAIN, {DOMAIN: {"type": "local", "host": "http://localhost:3000"}},
"almond",
{"almond": {"type": "local", "host": "http://localhost:3000"}},
) )
await hass.async_block_till_done() await hass.async_block_till_done()
@ -94,19 +91,19 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
"""Check full flow.""" """Check full flow."""
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
"almond", DOMAIN,
{ {
"almond": { DOMAIN: {
"type": "oauth2", "type": "oauth2",
"client_id": CLIENT_ID_VALUE, CONF_CLIENT_ID: CLIENT_ID_VALUE,
"client_secret": CLIENT_SECRET_VALUE, CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE,
}, },
"http": {"base_url": "https://example.com"}, "http": {"base_url": "https://example.com"},
}, },
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"almond", context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
state = config_entry_oauth2_flow._encode_jwt(hass, {"flow_id": result["flow_id"]}) state = config_entry_oauth2_flow._encode_jwt(hass, {"flow_id": result["flow_id"]})

View File

@ -3,6 +3,7 @@ import ambiclimate
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.ambiclimate import config_flow from homeassistant.components.ambiclimate import config_flow
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util import aiohttp from homeassistant.util import aiohttp
@ -71,8 +72,8 @@ async def test_full_flow_implementation(hass):
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "Ambiclimate" assert result["title"] == "Ambiclimate"
assert result["data"]["callback_url"] == "https://hass.com/api/ambiclimate" assert result["data"]["callback_url"] == "https://hass.com/api/ambiclimate"
assert result["data"]["client_secret"] == "secret" assert result["data"][CONF_CLIENT_SECRET] == "secret"
assert result["data"]["client_id"] == "id" assert result["data"][CONF_CLIENT_ID] == "id"
with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value=None): with patch("ambiclimate.AmbiclimateOAuth.get_access_token", return_value=None):
result = await flow.async_step_code("123ABC") result = await flow.async_step_code("123ABC")

View File

@ -3,6 +3,12 @@ import requests.exceptions
from homeassistant import config_entries, setup from homeassistant import config_entries, setup
from homeassistant.components.flume.const import DOMAIN from homeassistant.components.flume.const import DOMAIN
from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_PASSWORD,
CONF_USERNAME,
)
from tests.async_mock import MagicMock, patch from tests.async_mock import MagicMock, patch
@ -37,20 +43,20 @@ async def test_form(hass):
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{ {
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
}, },
) )
assert result2["type"] == "create_entry" assert result2["type"] == "create_entry"
assert result2["title"] == "test-username" assert result2["title"] == "test-username"
assert result2["data"] == { assert result2["data"] == {
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
} }
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1 assert len(mock_setup.mock_calls) == 1
@ -76,20 +82,20 @@ async def test_form_import(hass):
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_IMPORT}, context={"source": config_entries.SOURCE_IMPORT},
data={ data={
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
}, },
) )
assert result["type"] == "create_entry" assert result["type"] == "create_entry"
assert result["title"] == "test-username" assert result["title"] == "test-username"
assert result["data"] == { assert result["data"] == {
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
} }
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1 assert len(mock_setup.mock_calls) == 1
@ -111,10 +117,10 @@ async def test_form_invalid_auth(hass):
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{ {
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
}, },
) )
@ -136,10 +142,10 @@ async def test_form_cannot_connect(hass):
result2 = await hass.config_entries.flow.async_configure( result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
{ {
"username": "test-username", CONF_USERNAME: "test-username",
"password": "test-password", CONF_PASSWORD: "test-password",
"client_id": "client_id", CONF_CLIENT_ID: "client_id",
"client_secret": "client_secret", CONF_CLIENT_SECRET: "client_secret",
}, },
) )

View File

@ -2,6 +2,7 @@
import pytest import pytest
import homeassistant.components.google as google import homeassistant.components.google as google
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.async_mock import patch from tests.async_mock import patch
@ -24,7 +25,7 @@ def mock_google_setup(hass):
async def test_setup_component(hass, google_setup): async def test_setup_component(hass, google_setup):
"""Test setup component.""" """Test setup component."""
config = {"google": {"client_id": "id", "client_secret": "secret"}} config = {"google": {CONF_CLIENT_ID: "id", CONF_CLIENT_SECRET: "secret"}}
assert await async_setup_component(hass, "google", config) assert await async_setup_component(hass, "google", config)
@ -51,8 +52,8 @@ async def test_found_calendar(hass, google_setup, mock_next_event, test_calendar
"""Test when a calendar is found.""" """Test when a calendar is found."""
config = { config = {
"google": { "google": {
"client_id": "id", CONF_CLIENT_ID: "id",
"client_secret": "secret", CONF_CLIENT_SECRET: "secret",
"track_new_calendar": True, "track_new_calendar": True,
} }
} }

View File

@ -5,6 +5,7 @@ from homeassistant.components.home_connect.const import (
OAUTH2_AUTHORIZE, OAUTH2_AUTHORIZE,
OAUTH2_TOKEN, OAUTH2_TOKEN,
) )
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
CLIENT_ID = "1234" CLIENT_ID = "1234"
@ -17,7 +18,10 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
hass, hass,
"home_connect", "home_connect",
{ {
"home_connect": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET}, "home_connect": {
CONF_CLIENT_ID: CLIENT_ID,
CONF_CLIENT_SECRET: CLIENT_SECRET,
},
"http": {"base_url": "https://example.com"}, "http": {"base_url": "https://example.com"},
}, },
) )

View File

@ -6,6 +6,7 @@ from homeassistant.components.netatmo.const import (
OAUTH2_AUTHORIZE, OAUTH2_AUTHORIZE,
OAUTH2_TOKEN, OAUTH2_TOKEN,
) )
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.async_mock import patch from tests.async_mock import patch
@ -43,7 +44,7 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
hass, hass,
"netatmo", "netatmo",
{ {
"netatmo": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET}, "netatmo": {CONF_CLIENT_ID: CLIENT_ID, CONF_CLIENT_SECRET: CLIENT_SECRET},
"http": {"base_url": "https://example.com"}, "http": {"base_url": "https://example.com"},
}, },
) )

View File

@ -2,6 +2,7 @@
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
from homeassistant.components.plex import const from homeassistant.components.plex import const
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID,
CONF_HOST, CONF_HOST,
CONF_PORT, CONF_PORT,
CONF_TOKEN, CONF_TOKEN,
@ -35,7 +36,7 @@ MOCK_TOKEN = "secret_token"
DEFAULT_DATA = { DEFAULT_DATA = {
const.CONF_SERVER: MOCK_SERVERS[0][const.CONF_SERVER], const.CONF_SERVER: MOCK_SERVERS[0][const.CONF_SERVER],
const.PLEX_SERVER_CONFIG: { const.PLEX_SERVER_CONFIG: {
const.CONF_CLIENT_IDENTIFIER: "00000000-0000-0000-0000-000000000000", CONF_CLIENT_ID: "00000000-0000-0000-0000-000000000000",
CONF_TOKEN: MOCK_TOKEN, CONF_TOKEN: MOCK_TOKEN,
CONF_URL: f"https://{MOCK_SERVERS[0][CONF_HOST]}:{MOCK_SERVERS[0][CONF_PORT]}", CONF_URL: f"https://{MOCK_SERVERS[0][CONF_HOST]}:{MOCK_SERVERS[0][CONF_PORT]}",
CONF_VERIFY_SSL: True, CONF_VERIFY_SSL: True,

View File

@ -5,6 +5,7 @@ import pytest
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.point import DOMAIN, config_flow from homeassistant.components.point import DOMAIN, config_flow
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from tests.async_mock import AsyncMock, patch from tests.async_mock import AsyncMock, patch
@ -86,8 +87,8 @@ async def test_full_flow_implementation(
result = await flow.async_step_code("123ABC") result = await flow.async_step_code("123ABC")
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"]["refresh_args"] == { assert result["data"]["refresh_args"] == {
"client_id": "id", CONF_CLIENT_ID: "id",
"client_secret": "secret", CONF_CLIENT_SECRET: "secret",
} }
assert result["title"] == "john.doe@example.com" assert result["title"] == "john.doe@example.com"
assert result["data"]["token"] == {"access_token": "boo"} assert result["data"]["token"] == {"access_token": "boo"}

View File

@ -15,7 +15,13 @@ from homeassistant.components.reddit.sensor import (
CONF_SORT_BY, CONF_SORT_BY,
DOMAIN, DOMAIN,
) )
from homeassistant.const import CONF_MAXIMUM, CONF_PASSWORD, CONF_USERNAME from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_MAXIMUM,
CONF_PASSWORD,
CONF_USERNAME,
)
from homeassistant.setup import setup_component from homeassistant.setup import setup_component
from tests.async_mock import patch from tests.async_mock import patch
@ -24,8 +30,8 @@ from tests.common import get_test_home_assistant
VALID_CONFIG = { VALID_CONFIG = {
"sensor": { "sensor": {
"platform": DOMAIN, "platform": DOMAIN,
"client_id": "test_client_id", CONF_CLIENT_ID: "test_client_id",
"client_secret": "test_client_secret", CONF_CLIENT_SECRET: "test_client_secret",
CONF_USERNAME: "test_username", CONF_USERNAME: "test_username",
CONF_PASSWORD: "test_password", CONF_PASSWORD: "test_password",
"subreddits": ["worldnews", "news"], "subreddits": ["worldnews", "news"],
@ -35,8 +41,8 @@ VALID_CONFIG = {
VALID_LIMITED_CONFIG = { VALID_LIMITED_CONFIG = {
"sensor": { "sensor": {
"platform": DOMAIN, "platform": DOMAIN,
"client_id": "test_client_id", CONF_CLIENT_ID: "test_client_id",
"client_secret": "test_client_secret", CONF_CLIENT_SECRET: "test_client_secret",
CONF_USERNAME: "test_username", CONF_USERNAME: "test_username",
CONF_PASSWORD: "test_password", CONF_PASSWORD: "test_password",
"subreddits": ["worldnews", "news"], "subreddits": ["worldnews", "news"],
@ -48,8 +54,8 @@ VALID_LIMITED_CONFIG = {
INVALID_SORT_BY_CONFIG = { INVALID_SORT_BY_CONFIG = {
"sensor": { "sensor": {
"platform": DOMAIN, "platform": DOMAIN,
"client_id": "test_client_id", CONF_CLIENT_ID: "test_client_id",
"client_secret": "test_client_secret", CONF_CLIENT_SECRET: "test_client_secret",
CONF_USERNAME: "test_username", CONF_USERNAME: "test_username",
CONF_PASSWORD: "test_password", CONF_PASSWORD: "test_password",
"subreddits": ["worldnews", "news"], "subreddits": ["worldnews", "news"],

View File

@ -28,8 +28,6 @@ from homeassistant.components.smartthings.const import (
CONF_INSTALLED_APP_ID, CONF_INSTALLED_APP_ID,
CONF_INSTANCE_ID, CONF_INSTANCE_ID,
CONF_LOCATION_ID, CONF_LOCATION_ID,
CONF_OAUTH_CLIENT_ID,
CONF_OAUTH_CLIENT_SECRET,
CONF_REFRESH_TOKEN, CONF_REFRESH_TOKEN,
DATA_BROKERS, DATA_BROKERS,
DOMAIN, DOMAIN,
@ -39,7 +37,12 @@ from homeassistant.components.smartthings.const import (
) )
from homeassistant.config import async_process_ha_core_config from homeassistant.config import async_process_ha_core_config
from homeassistant.config_entries import CONN_CLASS_CLOUD_PUSH, SOURCE_USER, ConfigEntry from homeassistant.config_entries import CONN_CLASS_CLOUD_PUSH, SOURCE_USER, ConfigEntry
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_WEBHOOK_ID from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_WEBHOOK_ID,
)
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.async_mock import Mock, patch from tests.async_mock import Mock, patch
@ -217,8 +220,8 @@ def config_entry_fixture(hass, installed_app, location):
CONF_APP_ID: installed_app.app_id, CONF_APP_ID: installed_app.app_id,
CONF_LOCATION_ID: location.location_id, CONF_LOCATION_ID: location.location_id,
CONF_REFRESH_TOKEN: str(uuid4()), CONF_REFRESH_TOKEN: str(uuid4()),
CONF_OAUTH_CLIENT_ID: str(uuid4()), CONF_CLIENT_ID: str(uuid4()),
CONF_OAUTH_CLIENT_SECRET: str(uuid4()), CONF_CLIENT_SECRET: str(uuid4()),
} }
return MockConfigEntry( return MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,

View File

@ -11,13 +11,13 @@ from homeassistant.components.smartthings.const import (
CONF_APP_ID, CONF_APP_ID,
CONF_INSTALLED_APP_ID, CONF_INSTALLED_APP_ID,
CONF_LOCATION_ID, CONF_LOCATION_ID,
CONF_OAUTH_CLIENT_ID,
CONF_OAUTH_CLIENT_SECRET,
DOMAIN, DOMAIN,
) )
from homeassistant.config import async_process_ha_core_config from homeassistant.config import async_process_ha_core_config
from homeassistant.const import ( from homeassistant.const import (
CONF_ACCESS_TOKEN, CONF_ACCESS_TOKEN,
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
HTTP_FORBIDDEN, HTTP_FORBIDDEN,
HTTP_NOT_FOUND, HTTP_NOT_FOUND,
HTTP_UNAUTHORIZED, HTTP_UNAUTHORIZED,
@ -97,8 +97,8 @@ async def test_entry_created(hass, app, app_oauth_client, location, smartthings_
assert result["data"]["location_id"] == location.location_id assert result["data"]["location_id"] == location.location_id
assert result["data"]["access_token"] == token assert result["data"]["access_token"] == token
assert result["data"]["refresh_token"] == request.refresh_token assert result["data"]["refresh_token"] == request.refresh_token
assert result["data"]["client_secret"] == app_oauth_client.client_secret assert result["data"][CONF_CLIENT_SECRET] == app_oauth_client.client_secret
assert result["data"]["client_id"] == app_oauth_client.client_id assert result["data"][CONF_CLIENT_ID] == app_oauth_client.client_id
assert result["title"] == location.name assert result["title"] == location.name
entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,) entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,)
assert entry.unique_id == smartapp.format_unique_id( assert entry.unique_id == smartapp.format_unique_id(
@ -165,8 +165,8 @@ async def test_entry_created_from_update_event(
assert result["data"]["location_id"] == location.location_id assert result["data"]["location_id"] == location.location_id
assert result["data"]["access_token"] == token assert result["data"]["access_token"] == token
assert result["data"]["refresh_token"] == request.refresh_token assert result["data"]["refresh_token"] == request.refresh_token
assert result["data"]["client_secret"] == app_oauth_client.client_secret assert result["data"][CONF_CLIENT_SECRET] == app_oauth_client.client_secret
assert result["data"]["client_id"] == app_oauth_client.client_id assert result["data"][CONF_CLIENT_ID] == app_oauth_client.client_id
assert result["title"] == location.name assert result["title"] == location.name
entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,) entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,)
assert entry.unique_id == smartapp.format_unique_id( assert entry.unique_id == smartapp.format_unique_id(
@ -233,8 +233,8 @@ async def test_entry_created_existing_app_new_oauth_client(
assert result["data"]["location_id"] == location.location_id assert result["data"]["location_id"] == location.location_id
assert result["data"]["access_token"] == token assert result["data"]["access_token"] == token
assert result["data"]["refresh_token"] == request.refresh_token assert result["data"]["refresh_token"] == request.refresh_token
assert result["data"]["client_secret"] == app_oauth_client.client_secret assert result["data"][CONF_CLIENT_SECRET] == app_oauth_client.client_secret
assert result["data"]["client_id"] == app_oauth_client.client_id assert result["data"][CONF_CLIENT_ID] == app_oauth_client.client_id
assert result["title"] == location.name assert result["title"] == location.name
entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,) entry = next((entry for entry in hass.config_entries.async_entries(DOMAIN)), None,)
assert entry.unique_id == smartapp.format_unique_id( assert entry.unique_id == smartapp.format_unique_id(
@ -262,8 +262,8 @@ async def test_entry_created_existing_app_copies_oauth_client(
domain=DOMAIN, domain=DOMAIN,
data={ data={
CONF_APP_ID: app.app_id, CONF_APP_ID: app.app_id,
CONF_OAUTH_CLIENT_ID: oauth_client_id, CONF_CLIENT_ID: oauth_client_id,
CONF_OAUTH_CLIENT_SECRET: oauth_client_secret, CONF_CLIENT_SECRET: oauth_client_secret,
CONF_LOCATION_ID: str(uuid4()), CONF_LOCATION_ID: str(uuid4()),
CONF_INSTALLED_APP_ID: str(uuid4()), CONF_INSTALLED_APP_ID: str(uuid4()),
CONF_ACCESS_TOKEN: token, CONF_ACCESS_TOKEN: token,
@ -316,8 +316,8 @@ async def test_entry_created_existing_app_copies_oauth_client(
assert result["data"]["location_id"] == location.location_id assert result["data"]["location_id"] == location.location_id
assert result["data"]["access_token"] == token assert result["data"]["access_token"] == token
assert result["data"]["refresh_token"] == request.refresh_token assert result["data"]["refresh_token"] == request.refresh_token
assert result["data"]["client_secret"] == oauth_client_secret assert result["data"][CONF_CLIENT_SECRET] == oauth_client_secret
assert result["data"]["client_id"] == oauth_client_id assert result["data"][CONF_CLIENT_ID] == oauth_client_id
assert result["title"] == location.name assert result["title"] == location.name
entry = next( entry = next(
( (
@ -405,8 +405,8 @@ async def test_entry_created_with_cloudhook(
assert result["data"]["location_id"] == location.location_id assert result["data"]["location_id"] == location.location_id
assert result["data"]["access_token"] == token assert result["data"]["access_token"] == token
assert result["data"]["refresh_token"] == request.refresh_token assert result["data"]["refresh_token"] == request.refresh_token
assert result["data"]["client_secret"] == app_oauth_client.client_secret assert result["data"][CONF_CLIENT_SECRET] == app_oauth_client.client_secret
assert result["data"]["client_id"] == app_oauth_client.client_id assert result["data"][CONF_CLIENT_ID] == app_oauth_client.client_id
assert result["title"] == location.name assert result["title"] == location.name
entry = next( entry = next(
(entry for entry in hass.config_entries.async_entries(DOMAIN)), None, (entry for entry in hass.config_entries.async_entries(DOMAIN)), None,

View File

@ -5,14 +5,14 @@ import pytest
from homeassistant import config_entries, data_entry_flow, setup from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.components.somfy import DOMAIN, config_flow from homeassistant.components.somfy import DOMAIN, config_flow
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.async_mock import patch from tests.async_mock import patch
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
CLIENT_SECRET_VALUE = "5678"
CLIENT_ID_VALUE = "1234" CLIENT_ID_VALUE = "1234"
CLIENT_SECRET_VALUE = "5678"
@pytest.fixture() @pytest.fixture()
@ -56,18 +56,18 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
"""Check full flow.""" """Check full flow."""
assert await setup.async_setup_component( assert await setup.async_setup_component(
hass, hass,
"somfy", DOMAIN,
{ {
"somfy": { DOMAIN: {
"client_id": CLIENT_ID_VALUE, CONF_CLIENT_ID: CLIENT_ID_VALUE,
"client_secret": CLIENT_SECRET_VALUE, CONF_CLIENT_SECRET: CLIENT_SECRET_VALUE,
}, },
"http": {"base_url": "https://example.com"}, "http": {"base_url": "https://example.com"},
}, },
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
"somfy", context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
state = config_entry_oauth2_flow._encode_jwt(hass, {"flow_id": result["flow_id"]}) state = config_entry_oauth2_flow._encode_jwt(hass, {"flow_id": result["flow_id"]})
@ -97,7 +97,7 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
with patch("homeassistant.components.somfy.api.ConfigEntrySomfyApi"): with patch("homeassistant.components.somfy.api.ConfigEntrySomfyApi"):
result = await hass.config_entries.flow.async_configure(result["flow_id"]) result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["data"]["auth_implementation"] == "somfy" assert result["data"]["auth_implementation"] == DOMAIN
result["data"]["token"].pop("expires_at") result["data"]["token"].pop("expires_at")
assert result["data"]["token"] == { assert result["data"]["token"] == {
@ -107,8 +107,8 @@ async def test_full_flow(hass, aiohttp_client, aioclient_mock):
"expires_in": 60, "expires_in": 60,
} }
assert "somfy" in hass.config.components assert DOMAIN in hass.config.components
entry = hass.config_entries.async_entries("somfy")[0] entry = hass.config_entries.async_entries(DOMAIN)[0]
assert entry.state == config_entries.ENTRY_STATE_LOADED assert entry.state == config_entries.ENTRY_STATE_LOADED
assert await hass.config_entries.async_unload(entry.entry_id) assert await hass.config_entries.async_unload(entry.entry_id)

View File

@ -2,12 +2,9 @@
from spotipy import SpotifyException from spotipy import SpotifyException
from homeassistant import data_entry_flow, setup from homeassistant import data_entry_flow, setup
from homeassistant.components.spotify.const import ( from homeassistant.components.spotify.const import DOMAIN
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from tests.async_mock import patch from tests.async_mock import patch

View File

@ -10,14 +10,13 @@ from toonapilib.toonapilibexceptions import (
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.toon import config_flow from homeassistant.components.toon import config_flow
from homeassistant.components.toon.const import ( from homeassistant.components.toon.const import CONF_DISPLAY, CONF_TENANT, DOMAIN
from homeassistant.const import (
CONF_CLIENT_ID, CONF_CLIENT_ID,
CONF_CLIENT_SECRET, CONF_CLIENT_SECRET,
CONF_DISPLAY, CONF_PASSWORD,
CONF_TENANT, CONF_USERNAME,
DOMAIN,
) )
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.async_mock import patch from tests.async_mock import patch
@ -76,8 +75,8 @@ async def test_show_authenticate_form(hass):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"side_effect,reason", "side_effect,reason",
[ [
(InvalidConsumerKey, "client_id"), (InvalidConsumerKey, CONF_CLIENT_ID),
(InvalidConsumerSecret, "client_secret"), (InvalidConsumerSecret, CONF_CLIENT_SECRET),
(AgreementsRetrievalError, "no_agreements"), (AgreementsRetrievalError, "no_agreements"),
(Exception, "unknown_auth_fail"), (Exception, "unknown_auth_fail"),
], ],

View File

@ -3,6 +3,7 @@ from requests import HTTPError
from twitch.resources import Channel, Follow, Stream, Subscription, User from twitch.resources import Channel, Follow, Stream, Subscription, User
from homeassistant.components import sensor from homeassistant.components import sensor
from homeassistant.const import CONF_CLIENT_ID
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.async_mock import MagicMock, patch from tests.async_mock import MagicMock, patch
@ -11,14 +12,14 @@ ENTITY_ID = "sensor.channel123"
CONFIG = { CONFIG = {
sensor.DOMAIN: { sensor.DOMAIN: {
"platform": "twitch", "platform": "twitch",
"client_id": "1234", CONF_CLIENT_ID: "1234",
"channels": ["channel123"], "channels": ["channel123"],
} }
} }
CONFIG_WITH_OAUTH = { CONFIG_WITH_OAUTH = {
sensor.DOMAIN: { sensor.DOMAIN: {
"platform": "twitch", "platform": "twitch",
"client_id": "1234", CONF_CLIENT_ID: "1234",
"channels": ["channel123"], "channels": ["channel123"],
"token": "9876", "token": "9876",
} }

View File

@ -19,7 +19,12 @@ import homeassistant.components.http as http
import homeassistant.components.withings.const as const import homeassistant.components.withings.const as const
from homeassistant.config import async_process_ha_core_config from homeassistant.config import async_process_ha_core_config
from homeassistant.config_entries import SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_UNIT_SYSTEM, CONF_UNIT_SYSTEM_METRIC from homeassistant.const import (
CONF_CLIENT_ID,
CONF_CLIENT_SECRET,
CONF_UNIT_SYSTEM,
CONF_UNIT_SYSTEM_METRIC,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
@ -55,9 +60,9 @@ async def setup_hass(hass: HomeAssistant) -> dict:
api.DOMAIN: {"base_url": "http://localhost/"}, api.DOMAIN: {"base_url": "http://localhost/"},
http.DOMAIN: {"server_port": 8080}, http.DOMAIN: {"server_port": 8080},
const.DOMAIN: { const.DOMAIN: {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: profiles, const.CONF_PROFILES: profiles,
}, },
} }

View File

@ -15,7 +15,7 @@ from homeassistant.components.withings import (
const, const,
) )
from homeassistant.config import async_process_ha_core_config from homeassistant.config import async_process_ha_core_config
from homeassistant.const import STATE_UNKNOWN from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, STATE_UNKNOWN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .common import ( from .common import (
@ -55,9 +55,9 @@ def test_config_schema_basic_config() -> None:
"""Test schema.""" """Test schema."""
config_schema_validate( config_schema_validate(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1", "Person 2"], const.CONF_PROFILES: ["Person 1", "Person 2"],
} }
) )
@ -66,22 +66,22 @@ def test_config_schema_client_id() -> None:
"""Test schema.""" """Test schema."""
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1", "Person 2"], const.CONF_PROFILES: ["Person 1", "Person 2"],
} }
) )
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.CLIENT_ID: "", CONF_CLIENT_ID: "",
const.PROFILES: ["Person 1"], const.CONF_PROFILES: ["Person 1"],
} }
) )
config_schema_validate( config_schema_validate(
{ {
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.PROFILES: ["Person 1"], const.CONF_PROFILES: ["Person 1"],
} }
) )
@ -89,20 +89,20 @@ def test_config_schema_client_id() -> None:
def test_config_schema_client_secret() -> None: def test_config_schema_client_secret() -> None:
"""Test schema.""" """Test schema."""
config_schema_assert_fail( config_schema_assert_fail(
{const.CLIENT_ID: "my_client_id", const.PROFILES: ["Person 1"]} {CONF_CLIENT_ID: "my_client_id", const.CONF_PROFILES: ["Person 1"]}
) )
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "", CONF_CLIENT_SECRET: "",
const.PROFILES: ["Person 1"], const.CONF_PROFILES: ["Person 1"],
} }
) )
config_schema_validate( config_schema_validate(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1"], const.CONF_PROFILES: ["Person 1"],
} }
) )
@ -110,41 +110,41 @@ def test_config_schema_client_secret() -> None:
def test_config_schema_profiles() -> None: def test_config_schema_profiles() -> None:
"""Test schema.""" """Test schema."""
config_schema_assert_fail( config_schema_assert_fail(
{const.CLIENT_ID: "my_client_id", const.CLIENT_SECRET: "my_client_secret"} {CONF_CLIENT_ID: "my_client_id", CONF_CLIENT_SECRET: "my_client_secret"}
) )
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: "", const.CONF_PROFILES: "",
} }
) )
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: [], const.CONF_PROFILES: [],
} }
) )
config_schema_assert_fail( config_schema_assert_fail(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1", "Person 1"], const.CONF_PROFILES: ["Person 1", "Person 1"],
} }
) )
config_schema_validate( config_schema_validate(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1"], const.CONF_PROFILES: ["Person 1"],
} }
) )
config_schema_validate( config_schema_validate(
{ {
const.CLIENT_ID: "my_client_id", CONF_CLIENT_ID: "my_client_id",
const.CLIENT_SECRET: "my_client_secret", CONF_CLIENT_SECRET: "my_client_secret",
const.PROFILES: ["Person 1", "Person 2"], const.CONF_PROFILES: ["Person 1", "Person 2"],
} }
) )
@ -163,7 +163,7 @@ async def test_upgrade_token(
) -> None: ) -> None:
"""Test upgrading from old config data format to new one.""" """Test upgrading from old config data format to new one."""
config = await setup_hass(hass) config = await setup_hass(hass)
profiles = config[const.DOMAIN][const.PROFILES] profiles = config[const.DOMAIN][const.CONF_PROFILES]
await async_process_ha_core_config( await async_process_ha_core_config(
hass, {"internal_url": "http://example.local"}, hass, {"internal_url": "http://example.local"},
@ -197,7 +197,7 @@ async def test_upgrade_token(
"token_expiry": token.get("expires_at"), "token_expiry": token.get("expires_at"),
"token_type": token.get("type"), "token_type": token.get("type"),
"userid": token.get("userid"), "userid": token.get("userid"),
"client_id": token.get("my_client_id"), CONF_CLIENT_ID: token.get("my_client_id"),
"consumer_secret": token.get("my_consumer_secret"), "consumer_secret": token.get("my_consumer_secret"),
}, },
}, },
@ -228,7 +228,7 @@ async def test_upgrade_token(
assert token.get("expires_at") > time.time() assert token.get("expires_at") > time.time()
assert token.get("type") == "Bearer" assert token.get("type") == "Bearer"
assert token.get("userid") == "myuserid" assert token.get("userid") == "myuserid"
assert not token.get("client_id") assert not token.get(CONF_CLIENT_ID)
assert not token.get("consumer_secret") assert not token.get("consumer_secret")
@ -237,7 +237,7 @@ async def test_auth_failure(
) -> None: ) -> None:
"""Test auth failure.""" """Test auth failure."""
config = await setup_hass(hass) config = await setup_hass(hass)
profiles = config[const.DOMAIN][const.PROFILES] profiles = config[const.DOMAIN][const.CONF_PROFILES]
await async_process_ha_core_config( await async_process_ha_core_config(
hass, {"internal_url": "http://example.local"}, hass, {"internal_url": "http://example.local"},
@ -276,7 +276,7 @@ async def test_auth_failure(
async def test_full_setup(hass: HomeAssistant, aiohttp_client, aioclient_mock) -> None: async def test_full_setup(hass: HomeAssistant, aiohttp_client, aioclient_mock) -> None:
"""Test the whole component lifecycle.""" """Test the whole component lifecycle."""
config = await setup_hass(hass) config = await setup_hass(hass)
profiles = config[const.DOMAIN][const.PROFILES] profiles = config[const.DOMAIN][const.CONF_PROFILES]
await async_process_ha_core_config( await async_process_ha_core_config(
hass, {"internal_url": "http://example.local"}, hass, {"internal_url": "http://example.local"},