#!/usr/bin/env python3
"""Test FlexMeasures connection and create Cariflex assets via API."""
import asyncio
from flexmeasures_client import FlexMeasuresClient

async def main():
    # Connect
    client = FlexMeasuresClient(
        email="admin@digitribe.fr",
        password="Digitribe972",
        host="flexmeasures.digitribe.fr",
        ssl=True,
        request_timeout=60.0
    )
    
    print("Connected. Token:", client.access_token[:20] if client.access_token else "None")
    
    # Get user info
    try:
        user = await client.get_user()
        print("User:", user)
    except Exception as e:
        print(f"User error: {e}")
    
    # Get assets
    try:
        assets = await client.get_assets()
        print(f"Assets: {len(assets)}")
        for a in assets[:5]:
            print(f"  - {a}")
    except Exception as e:
        print(f"Assets error: {e}")
    
    # Get sensors
    try:
        sensors = await client.get_sensors()
        print(f"Sensors: {len(sensors)}")
    except Exception as e:
        print(f"Sensors error: {e}")
    
    await client.close()

asyncio.run(main())
