SONOFF eWelink CUBE API communication library (unofficial)
Project description
python-pip.sonoff-ewelink-cube-client-api
SONOFF eWelink CUBE API communication library (unofficial)
Supported devices:
- SONOFF iHost
- SONOFF NSPanel Pro (untested)
What is eWeLink CUBE?
eWeLink CUBE is a Smart Home Platform for local small-scale computing platforms, tailored and optimized from the eWeLink Smart Home Cloud Platform and hardware-adapted. More information: https://ewelink.cc/ewelink-cube/
Usage
Install pip package:
pip3 install sonoff-ewelink-cube-client-api
Example:
"""
Simple bootstrap example, see more in examples directory.
"""
import asyncio
import json
from sonoff_ewelink_cube_client_api import EWelinkCube
# Set None for disable formatting JSON output
PRINT_JSON_INDENT = 4
async def main():
# Create an instance of the API
ewelink_cube = EWelinkCube()
api_rest = ewelink_cube.create_api('iHost', ip='ihost.local')
# Get iHost access token method:
# After calling the [Access Token] interface, the iHost Web console page global
# pop-up box prompts the user to confirm the acquisition of the interface call credentials.
print(f'- Access token process: press link button on iHost device!')
access_token = await api_rest.getBridgeAT()
print(f'- Access token request: {access_token}')
# Set volume (0 - 100)
set_volume = 50
api_volume = await api_rest.updateBridgeConfig(volume=set_volume)
if api_volume and not api_volume["error"]:
print(f'- Volume set: {set_volume}%')
else:
print(f'- Volume set error: [{api_volume["error"]}] {api_volume["message"]}')
# iHost info
api_bridge_info = await api_rest.getBridgeInfo()
if api_bridge_info and not api_bridge_info["error"]:
print(f'- Bridge info: {json.dumps(api_bridge_info, indent=PRINT_JSON_INDENT)}')
# Devices list with some info
api_devices_list = await api_rest.getDeviceList()
if api_devices_list and not api_devices_list["error"]:
print(f'- Devices list: {json.dumps(api_devices_list, indent=PRINT_JSON_INDENT)}')
# Run the main function
if __name__ == "__main__":
asyncio.run(main())
See more in the examples directory.
Development and testing
# Start docker container (or use virtualenv)
docker run -rm -it -v "$(pwd)":/app -w /app python:3.11-slim /bin/bash
# Install packages and repository
pip3 install -r requirements-dev.txt
pip3 install .
# Pylint checks
pylint --recursive=y ./setup.py ./src ./examples
# Try examples
export LOG_LEVEL=DEBUG
export IHOST_BRIDGE_HOST_ADDRESS="192.168.1.110" # Use IP instead of ihost.local
export IHOST_BRIDGE_ACCES_TOKEN="uuid4-access-token" # Optional, see example codes
python3 examples/example_api.py
python3 examples/example_events.py
Tested devices:
- iHost - Firmware 1.6.1
Roadmap
✓ Integrated an API source from npm into Python
🔧 Fantastic features in the future: ;-)
- Create objects interfaces / enums by API documentation (payload, beep, etc...)
- Create additional API methods (non Open API, ex.: docker)
- Create test suites (unit / mock)
- CI/CD (ex.: Github or Travis)
- Git pre-hooks
- Errors handling
More informations
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
Close
Hashes for sonoff-ewelink-cube-client-api-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09632a3f7f60a479396b25e8f06b4d13c4b6b840baddb997f9a80e72aa1f2fcb |
|
MD5 | b9c18578f8f9ffb4eb620e6ee5b4bb01 |
|
BLAKE2b-256 | 27c0deea46ed62c07b0f6e8804ac6b76499ff1a132005f68325e24ca94698e2f |
Close
Hashes for sonoff_ewelink_cube_client_api-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f74b67df7af7817a1ff2c5f30bf3a652b59e9038d6c12a8e9ac41ef813af90 |
|
MD5 | 3b55bf5137cb81f68567cfe4ea6df433 |
|
BLAKE2b-256 | 4a102a20defe790300e5ee8c1d899eac2d3a4b8b9ff96ed6e3559368763862d1 |