# Heiman Connect Library

Python library for communicating with Heiman smart home devices.

## Installation

```bash
pip install heiman-connect
```

## Usage

```python
import asyncio
from heimanconnect import HeimanAuth, HeimanCloudClient, HeimanHttpClient
from heimanconnect.models import AuthInfo

async def main():
    # Initialize OAuth client
    oauth_client = HeimanOauthClient(
        client_id="app",
        redirect_url="http://localhost:8123/auth/external_callback",
    )
    
    # Generate auth URL for user authorization
    auth_url = oauth_client.gen_auth_url()
    print(f"Authorize at: {auth_url}")
    
    # After getting code from OAuth callback
    auth_info = await oauth_client.get_access_token_async(code="your_code")
    
    # Create HTTP client
    http_client = HeimanHttpClient(
        api_url="https://api.heiman.cn",
        client_id="app",
        access_token=auth_info.access_token,
    )
    
    # Create cloud client
    auth = HeimanAuth(oauth_client, auth_info)
    cloud_client = HeimanCloudClient(http_client, auth)
    
    # Get homes
    homes = await cloud_client.async_get_homes()
    
    # Get devices
    devices = await cloud_client.async_get_devices(home_id=homes[0].home_id)
    
    # Control device
    await cloud_client.async_control_device(
        device_id=device_id,
        property_identifier="Switch",
        value=True,
    )

asyncio.run(main())
```

## Features

- OAuth2 authentication
- HTTP API client
- MQTT real-time communication
- Device management
- Property control

## License

MIT License
