Python API client for Kerbl Welt IoT platform (AKO Smart Satellite electric fence monitors)
Project description
Kerblwelt API Client
Python API client for Kerbl Welt IoT platform, which powers the AKO Smart Satellite electric fence monitoring system.
Features
- Async/await support for efficient I/O operations
- Full type hints for better IDE support and type checking
- Automatic token management with refresh capability
- Comprehensive error handling with custom exceptions
- Data models using Python dataclasses
- Well-tested with pytest
Installation
pip install kerblwelt-api
Or for development:
git clone https://github.com/stgarrity/kerblwelt-api
cd kerblwelt-api
pip install -e ".[dev]"
Quick Start
import asyncio
from kerblwelt_api import KerblweltClient
async def main():
async with KerblweltClient() as client:
# Authenticate
await client.authenticate("your-email@example.com", "your-password")
# Get all devices
devices = await client.get_devices()
for device in devices:
print(f"Device: {device.description}")
print(f" Fence Voltage: {device.fence_voltage}V")
print(f" Battery: {device.battery_state}%")
print(f" Signal: {device.signal_quality}%")
print(f" Online: {device.is_online}")
print(f" Status: {'OK' if device.is_fence_voltage_ok else 'LOW VOLTAGE!'}")
if __name__ == "__main__":
asyncio.run(main())
Usage
Authentication
async with KerblweltClient() as client:
# Method 1: Authenticate with credentials
await client.authenticate("email@example.com", "password")
# Method 2: Restore previous session with tokens
client.set_tokens(
access_token="eyJhbGci...",
refresh_token="eyJhbGci..."
)
Get User Information
user = await client.get_user()
print(f"User: {user.email}")
print(f"Timezone: {user.timezone}")
print(f"Language: {user.language}")
Get Devices
# Get all Smart Satellite devices
devices = await client.get_devices()
# Get a specific device by ID
device = await client.get_device("device-uuid-here")
# Get device with event count
device_data = await client.get_all_device_data()
for device_id, (device, events) in device_data.items():
print(f"{device.description}: {events.new} new events")
Access Device Properties
device = devices[0]
# Basic info
print(device.description) # User-defined name
print(device.id) # Device UUID
print(device.identifier) # Serial number
# Status
print(device.is_online) # Online/offline
print(device.is_fence_voltage_ok) # Voltage above threshold
print(device.is_battery_low) # Battery below 20%
# Measurements
print(device.fence_voltage) # Current voltage (V)
print(device.battery_voltage) # Battery voltage (V)
print(device.battery_state) # Battery percentage (0-100)
print(device.signal_quality) # Signal strength (0-100)
# Thresholds
print(device.fence_voltage_alarm_threshold) # Alert threshold (V)
# Timestamps
print(device.registered_at) # Registration date
print(device.first_online_at) # First connection
print(device.offline_since) # Last offline time
Token Refresh
The client automatically handles token expiration. You can also manually refresh:
try:
devices = await client.get_devices()
except TokenExpiredError:
await client.refresh_token()
devices = await client.get_devices()
Error Handling
from kerblwelt_api import (
InvalidCredentialsError,
DeviceNotFoundError,
APIError,
ConnectionError,
)
try:
await client.authenticate("email@example.com", "wrong-password")
except InvalidCredentialsError:
print("Invalid email or password")
except ConnectionError:
print("Cannot connect to Kerbl Welt API")
except APIError as e:
print(f"API error: {e}")
API Reference
KerblweltClient
Main client class for interacting with Kerbl Welt API.
Methods:
authenticate(email: str, password: str) -> None- Authenticate with credentialsset_tokens(access_token: str, refresh_token: str) -> None- Set tokens manuallyrefresh_token() -> None- Refresh the access tokenget_user() -> User- Get current user informationget_devices() -> list[SmartSatelliteDevice]- Get all Smart Satellite devicesget_device(device_id: str) -> SmartSatelliteDevice- Get specific deviceget_device_event_count(device_id: str) -> DeviceEventCount- Get event countget_all_device_data() -> dict- Get all devices with event countsclose() -> None- Close the client session
Properties:
is_authenticated: bool- Check if client is authenticated
SmartSatelliteDevice
Represents an AKO Smart Satellite electric fence monitor.
Key Attributes:
id: str- Device UUIDdescription: str- User-defined device namefence_voltage: int- Current fence voltage in voltsbattery_voltage: float- Battery voltage in voltsbattery_state: int- Battery percentage (0-100)signal_quality: int- Signal strength (0-100)is_online: bool- Device online statusfence_voltage_alarm_threshold: int- Alert threshold in volts
Helper Properties:
is_fence_voltage_ok: bool- Voltage above thresholdis_battery_low: bool- Battery below 20%
Exceptions
All exceptions inherit from KerblweltError:
AuthenticationError- Base authentication errorInvalidCredentialsError- Wrong email/passwordTokenExpiredError- Token has expiredTokenRefreshError- Token refresh failed
APIError- API request failedConnectionError- Network connection failedDeviceNotFoundError- Device ID not foundRateLimitError- API rate limit exceededValidationError- Input validation failed
Development
Setup
# Clone repository
git clone https://github.com/stgarrity/kerblwelt-api
cd kerblwelt-api
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=kerblwelt_api
# Run specific test file
pytest tests/test_client.py
Code Quality
# Format code
black kerblwelt_api tests
# Lint code
ruff check kerblwelt_api tests
# Type checking
mypy kerblwelt_api
Requirements
- Python 3.11 or higher
- aiohttp 3.9.0 or higher
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Acknowledgments
- Built for the Kerbl Welt IoT platform
- Powers AKO Smart Satellite electric fence monitors
- Designed for integration with Home Assistant
Links
Support
For issues and questions:
- GitHub Issues
- Email: sgarrity@gmail.com
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 kerblwelt_api-0.1.0.tar.gz.
File metadata
- Download URL: kerblwelt_api-0.1.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
376ffa168defc077d932756c99683daf9dbf3e3888ff0cc3a92b6fb071698d7a
|
|
| MD5 |
82ff1e5fcf11029f28804a2fe459a518
|
|
| BLAKE2b-256 |
f51cba4f86ff86898dcbd0969ac668ba2a422227982cb76fd8d0b547ab9984d9
|
File details
Details for the file kerblwelt_api-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kerblwelt_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75b7fd398d294bbd4967bcc2555a3a648edf66bab3d0eac35b2ab2db2cb7fe45
|
|
| MD5 |
c85126383c66778328b2d7e92bc219de
|
|
| BLAKE2b-256 |
660d40e780d3fae433447c314b5435188b0083dccf4cd4e48df66bf97a5bd792
|