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_stateto handle bridge IDs reliably.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybticino-1.1.tar.gz.
File metadata
- Download URL: pybticino-1.1.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd0d66e7995a695ec8696f9733515e05ab40fabd34d85ca1176af519527dc463
|
|
| MD5 |
8833be8052a010cb25d9ebb1cca36b2d
|
|
| BLAKE2b-256 |
fc40b5712726ca246fcf794e8e40fbd452213e04fb83b794a3490fd24045207f
|
File details
Details for the file pybticino-1.1-py3-none-any.whl.
File metadata
- Download URL: pybticino-1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b22ed8d33b9d2230c5fecb59623e71577f5ad219490af27e83c83aae826ddc8
|
|
| MD5 |
9630531abf2434a66ae9f775788c5a07
|
|
| BLAKE2b-256 |
44481c897bb76d03f7ff4c51a25a9a33114b572e723d5ec353dea54a89f1efeb
|