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 logging
from pybticino import AuthHandler, ApiClient, ApiError, AuthError

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

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

try:
    # 1. Authenticate
    auth = AuthHandler(USERNAME, PASSWORD)
    # The first call to auth.access_token will trigger authentication
    print(f"Access Token obtained: {auth.access_token[:10]}...") # Print truncated token

    # 2. Create API Client
    client = ApiClient(auth)

    # 3. Get Homes Data
    print("\nFetching homes data...")
    homes_data = client.get_homes_data()
    print(f"Found {len(homes_data.get('body', {}).get('homes', []))} homes.")

    # Example: Get the first home ID
    home_id = None
    if homes_data.get('body', {}).get('homes'):
        home_id = homes_data['body']['homes'][0]['id']
        print(f"Using Home ID: {home_id}")

        # 4. Get Home Status (if home_id found)
        print(f"\nFetching status for home {home_id}...")
        home_status = client.get_home_status(home_id)
        print(f"Home status retrieved. Found {len(home_status.get('body', {}).get('home', {}).get('modules', []))} modules.")
        # print(home_status) # Uncomment to see full status

        # 5. Get Events (if home_id found)
        print(f"\nFetching events for home {home_id}...")
        events = client.get_events(home_id=home_id, size=5) # Get last 5 events
        print(f"Retrieved {len(events.get('body', {}).get('home', {}).get('events', []))} events.")
        # print(events) # Uncomment to see full events

        # 6. Example: Set State (Use with caution!)
        # Find a module ID to control (e.g., a door lock 'BNDL')
        # module_to_unlock_id = None
        # if home_status.get('body', {}).get('home', {}).get('modules'):
        #     for module in home_status['body']['home']['modules']:
        #         if module.get('type') == 'BNDL': # Example: Find a door lock
        #              module_to_unlock_id = module.get('id')
        #              print(f"\nFound door lock module: {module_to_unlock_id}")
        #              break
        #
        # if module_to_unlock_id:
        #     try:
        #         print(f"Attempting to unlock module {module_to_unlock_id}...")
        #         # Ensure you know the correct state key (e.g., 'lock')
        #         result = client.set_module_state(home_id, module_to_unlock_id, {'lock': False})
        #         print(f"Set state result: {result}")
        #     except ApiError as e:
        #         print(f"Error setting state: {e}")


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}")

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.
  • Add methods for remaining API endpoints found in logs.
  • Implement proper data models (models.py).
  • Add comprehensive unit tests.
  • Improve error handling and documentation.
  • Refine set_module_state to handle bridge IDs reliably.

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.3.tar.gz (42.7 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.3-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybticino-1.3.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pybticino-1.3.tar.gz
Algorithm Hash digest
SHA256 094062cd2530e8bbe1cf459718995ed4c8e36b70e263cb44176c02b167f8a118
MD5 8b8623b408b38066fa72d6acc4fb42b8
BLAKE2b-256 adb68e730f8f6d2048b07fa0fe61ce19269bd383f8408b1d61f74469dc70ec2c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybticino-1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pybticino-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8a1c46b2ffa97732f2c26d39652ca600cf802d48f9865eecb6e593551e9b0094
MD5 706ca99b5e57c5d907eccf45be4e5439
BLAKE2b-256 12dd373f80ed0af5c27c0a649ecd50a4efa73995c4d833a89bc23311670c8b1c

See more details on using hashes here.

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