コード例 #1
0
    async def async_generate_authorize_url(self, flow_id: str) -> str:
        """Generate a url for the user to authorize."""
        helper = account_link.AuthorizeAccountHelper(
            self.hass.data[DOMAIN], self.service
        )
        authorize_url = await helper.async_get_authorize_url()

        async def await_tokens():
            """Wait for tokens and pass them on when received."""
            try:
                tokens = await helper.async_get_tokens()

            except asyncio.TimeoutError:
                _LOGGER.info("Timeout fetching tokens for flow %s", flow_id)
            except account_link.AccountLinkException as err:
                _LOGGER.info(
                    "Failed to fetch tokens for flow %s: %s", flow_id, err.code
                )
            else:
                await self.hass.config_entries.flow.async_configure(
                    flow_id=flow_id, user_input=tokens
                )

        self.hass.async_create_task(await_tokens())

        return authorize_url
コード例 #2
0
async def create_helper_instance(
        aiohttp_client, handle_server_msgs,
        service) -> account_link.AuthorizeAccountHelper:
    """Create a auth helper instance."""
    client = await create_account_link_server(aiohttp_client,
                                              handle_server_msgs)
    mock_cloud = Mock(client=Mock(websession=Mock(ws_connect=Mock(
        return_value=mock_coro(client)))))
    return account_link.AuthorizeAccountHelper(mock_cloud, service)