function test_remarkable_authentication
Asynchronous test function that validates reMarkable Cloud authentication and verifies access to the root folder by listing its contents.
/tf/active/vicechatdev/e-ink-llm/test_remarkable.py
16 - 71
moderate
Purpose
This function serves as a diagnostic tool to test the complete authentication flow with reMarkable Cloud services. It verifies that the rmcl library is installed, initializes the RemarkableCloudManager, authenticates with the cloud service, and validates access by retrieving and displaying the root folder contents. It provides detailed console output with status indicators to help users troubleshoot authentication issues and includes instructions for first-time authentication setup.
Source Code
async def test_remarkable_authentication():
"""Test reMarkable Cloud authentication"""
print("๐งช Testing reMarkable Cloud Authentication")
print("=" * 50)
try:
# Check if rmcl is available
try:
import rmcl
print("โ
rmcl library is available")
except ImportError:
print("โ rmcl library not found. Install with: pip install rmcl")
return False
# Initialize cloud manager
cloud_manager = RemarkableCloudManager()
print("โ
RemarkableCloudManager initialized")
# Test authentication (this will use existing tokens if available)
print("๐ Testing authentication...")
auth_result = await cloud_manager.authenticate()
if auth_result:
print("โ
Authentication successful!")
# Test folder listing
print("๐ Testing folder access...")
root_folder = await cloud_manager.get_folder_by_path("/")
if root_folder:
print(f"โ
Root folder accessed successfully")
print(f" Root folder has {len(root_folder.children)} items")
# List some items
for i, child in enumerate(root_folder.children[:5]): # Show first 5 items
item_type = "๐" if hasattr(child, 'children') else "๐"
print(f" {item_type} {child.name}")
if len(root_folder.children) > 5:
print(f" ... and {len(root_folder.children) - 5} more items")
return True
else:
print("โ Failed to access root folder")
return False
else:
print("โ Authentication failed")
print(" To authenticate for the first time:")
print(" 1. Go to https://my.remarkable.com/connect/desktop")
print(" 2. Generate a one-time code")
print(" 3. Run: python test_remarkable.py --code YOUR_CODE")
return False
except Exception as e:
print(f"โ Test failed with error: {e}")
return False
Return Value
Returns a boolean value: True if authentication and folder access are successful, False if any step fails (missing library, authentication failure, or folder access failure). May also return False implicitly if an exception occurs during execution.
Dependencies
asynciosyspathlibrmclremarkable_cloud
Required Imports
import asyncio
import sys
from pathlib import Path
from remarkable_cloud import RemarkableCloudManager
Conditional/Optional Imports
These imports are only needed under specific conditions:
import rmcl
Condition: Required for reMarkable Cloud API functionality; checked at runtime with try-except block
Required (conditional)Usage Example
import asyncio
from pathlib import Path
from remarkable_cloud import RemarkableCloudManager
async def main():
# Run the authentication test
result = await test_remarkable_authentication()
if result:
print("Authentication test passed!")
else:
print("Authentication test failed. Check output for details.")
# Execute the async function
if __name__ == "__main__":
asyncio.run(main())
Best Practices
- This function must be called with asyncio.run() or within an existing async context
- Ensure rmcl library is installed before running: pip install rmcl
- For first-time authentication, obtain a one-time code from https://my.remarkable.com/connect/desktop
- The function provides detailed console output for debugging; monitor the output for specific error messages
- Authentication tokens are cached by the rmcl library, so subsequent runs will use existing credentials
- The function gracefully handles missing dependencies and provides installation instructions
- Network connectivity is required for cloud authentication and folder access
- Consider wrapping calls to this function in try-except blocks for production use
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_remarkable_auth 92.7% similar
-
function test_remarkable_with_code 86.3% similar
-
function main_v58 85.6% similar
-
function test_remarkable_discovery 78.8% similar
-
function main_v103 74.8% similar