async def test_implementation_provider(hass, local_impl):
    """Test providing an implementation provider."""
    assert (await config_entry_oauth2_flow.async_get_implementations(
        hass, TEST_DOMAIN) == {})

    mock_domain_with_impl = "some_domain"

    config_entry_oauth2_flow.async_register_implementation(
        hass, mock_domain_with_impl, local_impl)

    assert await config_entry_oauth2_flow.async_get_implementations(
        hass, mock_domain_with_impl) == {
            TEST_DOMAIN: local_impl
        }

    provider_source = []

    async def async_provide_implementation(hass, domain):
        """Mock implementation provider."""
        return provider_source

    config_entry_oauth2_flow.async_add_implementation_provider(
        hass, "cloud", async_provide_implementation)

    assert await config_entry_oauth2_flow.async_get_implementations(
        hass, mock_domain_with_impl) == {
            TEST_DOMAIN: local_impl
        }

    provider_source.append(
        config_entry_oauth2_flow.LocalOAuth2Implementation(
            hass, "cloud", CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL))

    assert await config_entry_oauth2_flow.async_get_implementations(
        hass, mock_domain_with_impl) == {
            TEST_DOMAIN: local_impl,
            "cloud": provider_source[0]
        }

    provider_source.append(
        config_entry_oauth2_flow.LocalOAuth2Implementation(
            hass, "other", CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL))

    assert await config_entry_oauth2_flow.async_get_implementations(
        hass, mock_domain_with_impl) == {
            TEST_DOMAIN: local_impl,
            "cloud": provider_source[0],
            "other": provider_source[1],
        }
Exemple #2
0
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
    """Set up Application Credentials."""
    hass.data[DOMAIN] = {}

    id_manager = collection.IDManager()
    storage_collection = ApplicationCredentialsStorageCollection(
        Store(hass, STORAGE_VERSION, STORAGE_KEY),
        logging.getLogger(f"{__name__}.storage_collection"),
        id_manager,
    )
    await storage_collection.async_load()
    hass.data[DOMAIN][DATA_STORAGE] = storage_collection

    collection.StorageCollectionWebsocket(storage_collection, DOMAIN, DOMAIN,
                                          CREATE_FIELDS,
                                          UPDATE_FIELDS).async_setup(hass)

    websocket_api.async_register_command(hass, handle_integration_list)

    config_entry_oauth2_flow.async_add_implementation_provider(
        hass, DOMAIN, _async_provide_implementation)

    return True
Exemple #3
0
def async_setup(hass: HomeAssistant):
    """Set up cloud account link."""
    config_entry_oauth2_flow.async_add_implementation_provider(
        hass, DOMAIN, async_provide_implementation)