Skip to main content

Simple API to access BTicino/Legrand Classe 100X/300X devices

Project description

pybticino

A Python library for interacting with the BTicino/Netatmo API (based on reverse-engineered logs).

Disclaimer: This library is based on unofficial observations of the Netatmo API used by BTicino devices. API endpoints, parameters, and responses may change without notice. Use at your own risk.

Installation

# TODO: Add installation instructions once published or ready for local install
# pip install .

Basic Usage

import asyncio
import logging
from pybticino import AuthHandler, AsyncAccount, ApiError, AuthError

# Configure logging (optional)
logging.basicConfig(level=logging.INFO)

# Replace with your actual credentials
USERNAME = "your_email@example.com"
PASSWORD = "your_password"

async def main():
    auth = None
    try:
        # 1. Create AuthHandler
        auth = AuthHandler(USERNAME, PASSWORD)
        
        # 2. Create AsyncAccount (manages authentication automatically)
        account = AsyncAccount(auth)

        # 3. Get Homes Data and populate models
        print("Fetching homes data...")
        await account.async_update_topology()
        print(f"Found {len(account.homes)} homes.")
        
        # Access structured home data
        for home_id, home in account.homes.items():
            print(f"Home: {home.name} (ID: {home_id})")
            print(f"  Modules: {len(home.modules)}")
            
            # 4. Get Home Status
            print(f"\nFetching status for home {home_id}...")
            status = await account.async_get_home_status(home_id)
            
            # 5. Get Events
            print(f"Fetching recent events...")
            events = await account.async_get_events(home_id, size=5)
            
            # 6. Example: Control a device (Use with caution!)
            # for module in home.modules:
            #     if module.type == 'BNDL':  # Door lock
            #         print(f"Unlocking {module.name}...")
            #         result = await account.async_set_module_state(
            #             home_id, module.id, {'lock': False}
            #         )
            #         print(f"Result: {result}")
            #         break

    except AuthError as e:
        print(f"Authentication Error: {e}")
    except ApiError as e:
        print(f"API Error: Status={e.status_code}, Message={e.error_message}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")
    finally:
        # Clean up session
        if auth:
            await auth.close_session()

# Run the async main function
if __name__ == "__main__":
    asyncio.run(main())

WebSocket Usage (Real-time notifications)

import asyncio
from pybticino import AuthHandler, WebsocketClient

async def handle_message(message):
    """Handle incoming WebSocket messages"""
    print(f"Received: {message}")
    # Process different message types here

async def websocket_example():
    auth = AuthHandler("your_email@example.com", "your_password")
    
    # Create WebSocket client with message handler
    ws_client = WebsocketClient(auth, handle_message)
    
    try:
        # Connect and run forever (with auto-reconnection)
        await ws_client.run_forever(reconnect_delay=30)
    except KeyboardInterrupt:
        print("Stopping WebSocket client...")
    finally:
        await ws_client.disconnect()
        await auth.close_session()

if __name__ == "__main__":
    asyncio.run(websocket_example())

Features

  • Authentication via username/password (OAuth2 Password Grant)
  • Get Homes Data (/api/homesdata)
  • Get Home Status (/syncapi/v1/homestatus)
  • Set Module State (/syncapi/v1/setstate)
  • Get Events (/api/getevents)

TODO

  • Implement token refresh logic.
  • Implement handling for WebSocket connections.
  • Implement proper data models (models.py).
  • Refine set_module_state to handle bridge IDs reliably.
  • Enhance WebSocket integration with main API client for real-time state updates
  • Add event-driven model updates from WebSocket messages
  • Add methods for remaining API endpoints found in logs
  • Add comprehensive unit tests
  • Improve error handling and documentation

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybticino-1.5.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybticino-1.5.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file pybticino-1.5.0.tar.gz.

File metadata

  • Download URL: pybticino-1.5.0.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pybticino-1.5.0.tar.gz
Algorithm Hash digest
SHA256 9b4d3be8e266df743e327bd8e8237163a3258c1458099b2f21092dc0acbc6e0a
MD5 561604973d71e9e599adb088b48a78c7
BLAKE2b-256 36048f05a08e3ebf4a51bd2aaf5d18d6e9b6a4d1383a79bb5220735c56d19b7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybticino-1.5.0.tar.gz:

Publisher: release.yml on k-the-hidden-hero/pybticino

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pybticino-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pybticino-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pybticino-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 693f3b97ea8bd58efd882aefc2dc7d232e289cc8fe2cdcd65e829c09a522cb91
MD5 36288da90acdf21adcf50f567953f7d3
BLAKE2b-256 74e0e54ed7f1f5a62660ee94588d158dd98f6bdb3c81634a7335ed5034688cd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybticino-1.5.0-py3-none-any.whl:

Publisher: release.yml on k-the-hidden-hero/pybticino

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page