async def async_setup(opp: OpenPeerPower, config: dict): """Set up the Smappee component.""" opp.data[DOMAIN] = {} if DOMAIN not in config: return True client_id = config[DOMAIN][CONF_CLIENT_ID] opp.data[DOMAIN][client_id] = {} # decide platform platform = "PRODUCTION" if client_id == "openpeerpower_f2": platform = "ACCEPTANCE" elif client_id == "openpeerpower_f3": platform = "DEVELOPMENT" opp.data[DOMAIN][CONF_PLATFORM] = platform config_flow.SmappeeFlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET], AUTHORIZE_URL[platform], TOKEN_URL[platform], ), ) return True
async def async_setup(opp: OpenPeerPower, config: dict): """Set up the Netatmo component.""" opp.data[DOMAIN] = { DATA_PERSONS: {}, DATA_DEVICE_IDS: {}, DATA_SCHEDULES: {}, DATA_HOMES: {}, DATA_EVENTS: {}, DATA_CAMERAS: {}, } if DOMAIN not in config: return True config_flow.NetatmoFlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET], OAUTH2_AUTHORIZE, OAUTH2_TOKEN, ), ) return True
async def mock_impl(opp): """Mock implementation.""" await setup.async_setup_component(opp, "http", {}) impl = config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, CLIENT_ID, CLIENT_SECRET, OAUTH2_AUTHORIZE, OAUTH2_TOKEN, ) config_flow.OAuth2FlowHandler.async_register_implementation(opp, impl) return impl
async def async_setup(opp: OpenPeerPower, config: ConfigType) -> bool: """Set up the Spotify integration.""" if DOMAIN not in config: return True if CONF_CLIENT_ID in config[DOMAIN]: config_flow.SpotifyFlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET], "https://accounts.spotify.com/authorize", "https://accounts.spotify.com/api/token", ), ) return True
async def async_setup(opp: OpenPeerPower, config: dict): """Set up the NEW_NAME component.""" opp.data[DOMAIN] = {} if DOMAIN not in config: return True config_flow.OAuth2FlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET], OAUTH2_AUTHORIZE, OAUTH2_TOKEN, ), ) return True
async def async_setup(opp, config): """Set up the Somfy component.""" opp.data[DOMAIN] = {} domain_config = config.get(DOMAIN, {}) opp.data[DOMAIN][CONF_OPTIMISTIC] = domain_config.get(CONF_OPTIMISTIC, False) if CONF_CLIENT_ID in domain_config: config_flow.SomfyFlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET], "https://accounts.somfy.com/oauth/oauth/v2/auth", "https://accounts.somfy.com/oauth/oauth/v2/token", ), ) return True
async def test_implementation_provider(opp, local_impl): """Test providing an implementation provider.""" assert (await config_entry_oauth2_flow.async_get_implementations( opp, TEST_DOMAIN) == {}) mock_domain_with_impl = "some_domain" config_entry_oauth2_flow.async_register_implementation( opp, mock_domain_with_impl, local_impl) assert await config_entry_oauth2_flow.async_get_implementations( opp, mock_domain_with_impl) == { TEST_DOMAIN: local_impl } provider_source = {} async def async_provide_implementation(opp, domain): """Mock implementation provider.""" return provider_source.get(domain) config_entry_oauth2_flow.async_add_implementation_provider( opp, "cloud", async_provide_implementation) assert await config_entry_oauth2_flow.async_get_implementations( opp, mock_domain_with_impl) == { TEST_DOMAIN: local_impl } provider_source[ mock_domain_with_impl] = config_entry_oauth2_flow.LocalOAuth2Implementation( opp, "cloud", CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL) assert await config_entry_oauth2_flow.async_get_implementations( opp, mock_domain_with_impl) == { TEST_DOMAIN: local_impl, "cloud": provider_source[mock_domain_with_impl] }
async def async_setup(opp, config): """Set up the Almond component.""" opp.data[DOMAIN] = {} if DOMAIN not in config: return True conf = config[DOMAIN] host = conf[CONF_HOST] if conf[CONF_TYPE] == TYPE_OAUTH2: config_flow.AlmondFlowHandler.async_register_implementation( opp, config_entry_oauth2_flow.LocalOAuth2Implementation( opp, DOMAIN, conf[CONF_CLIENT_ID], conf[CONF_CLIENT_SECRET], f"{host}/me/api/oauth2/authorize", f"{host}/me/api/oauth2/token", ), ) return True if not opp.config_entries.async_entries(DOMAIN): opp.async_create_task( opp.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={ "type": TYPE_LOCAL, "host": conf[CONF_HOST] }, )) return True
async def local_impl(opp): """Local implementation.""" assert await setup.async_setup_component(opp, "http", {}) return config_entry_oauth2_flow.LocalOAuth2Implementation( opp, TEST_DOMAIN, CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL)