# 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:
```sh
pip3 install sonoff-ewelink-cube-client-api
```
Example:
```sh
"""
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](https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api/tree/main/examples) directory.
---
## Development and testing
```sh
# 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](https://www.npmjs.com/package/node-red-contrib-ewelink-cube) 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
- https://ewelink.cc/ewelink-cube/
- https://ewelink.cc/ewelink-cube/open-api/
- https://sonoff.tech/ihost-user-guides/api/
- https://www.npmjs.com/package/node-red-contrib-ewelink-cube
Raw data
{
"_id": null,
"home_page": "https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api",
"name": "sonoff-ewelink-cube-client-api",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "sonoff ewelink cube api openapi ihost nspanel library asyncio",
"author": "sipimokus",
"author_email": "sipimokus@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/27/c0/deea46ed62c07b0f6e8804ac6b76499ff1a132005f68325e24ca94698e2f/sonoff-ewelink-cube-client-api-0.0.2.tar.gz",
"platform": null,
"description": "# python-pip.sonoff-ewelink-cube-client-api\n\nSONOFF eWelink CUBE API communication library (unofficial)\n\nSupported devices:\n- SONOFF iHost\n- SONOFF NSPanel Pro (untested)\n\n### What is eWeLink CUBE?\n\neWeLink 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.\nMore information: https://ewelink.cc/ewelink-cube/\n\n\n---\n## Usage\n\nInstall pip package:\n```sh\npip3 install sonoff-ewelink-cube-client-api\n```\n\nExample:\n```sh\n\"\"\"\nSimple bootstrap example, see more in examples directory.\n\"\"\"\n\nimport asyncio\nimport json\n\nfrom sonoff_ewelink_cube_client_api import EWelinkCube\n\n# Set None for disable formatting JSON output\nPRINT_JSON_INDENT = 4\n\n\nasync def main():\n # Create an instance of the API\n ewelink_cube = EWelinkCube()\n api_rest = ewelink_cube.create_api('iHost', ip='ihost.local')\n\n # Get iHost access token method:\n # After calling the [Access Token] interface, the iHost Web console page global\n # pop-up box prompts the user to confirm the acquisition of the interface call credentials.\n print(f'- Access token process: press link button on iHost device!')\n access_token = await api_rest.getBridgeAT()\n print(f'- Access token request: {access_token}')\n\n # Set volume (0 - 100)\n set_volume = 50\n api_volume = await api_rest.updateBridgeConfig(volume=set_volume)\n if api_volume and not api_volume[\"error\"]:\n print(f'- Volume set: {set_volume}%')\n else:\n print(f'- Volume set error: [{api_volume[\"error\"]}] {api_volume[\"message\"]}')\n\n #\u00a0iHost info\n api_bridge_info = await api_rest.getBridgeInfo()\n if api_bridge_info and not api_bridge_info[\"error\"]:\n print(f'- Bridge info: {json.dumps(api_bridge_info, indent=PRINT_JSON_INDENT)}')\n\n # Devices list with some info\n api_devices_list = await api_rest.getDeviceList()\n if api_devices_list and not api_devices_list[\"error\"]:\n print(f'- Devices list: {json.dumps(api_devices_list, indent=PRINT_JSON_INDENT)}')\n\n\n# Run the main function\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\nSee more in the [examples](https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api/tree/main/examples) directory.\n\n\n---\n## Development and testing\n\n```sh\n# Start docker container (or use virtualenv)\ndocker run -rm -it -v \"$(pwd)\":/app -w /app python:3.11-slim /bin/bash\n\n# Install packages and repository\npip3 install -r requirements-dev.txt\npip3 install .\n\n# Pylint checks\npylint --recursive=y ./setup.py ./src ./examples\n\n# Try examples\nexport LOG_LEVEL=DEBUG\nexport IHOST_BRIDGE_HOST_ADDRESS=\"192.168.1.110\" # Use IP instead of ihost.local\nexport IHOST_BRIDGE_ACCES_TOKEN=\"uuid4-access-token\" # Optional, see example codes\n\npython3 examples/example_api.py\npython3 examples/example_events.py\n```\n\nTested devices:\n- iHost - Firmware 1.6.1\n\n\n---\n## Roadmap\n\n\u2713 Integrated an API source from [npm](https://www.npmjs.com/package/node-red-contrib-ewelink-cube) into Python\n\n\ud83d\udd27 Fantastic features in the future: ;-)\n- Create objects interfaces / enums by API documentation (payload, beep, etc...)\n- Create additional API methods (non Open API, ex.: docker)\n- Create test suites (unit / mock)\n- CI/CD (ex.: Github or Travis)\n- Git pre-hooks\n- Errors handling\n\n---\n## More informations\n\n- https://ewelink.cc/ewelink-cube/\n- https://ewelink.cc/ewelink-cube/open-api/\n- https://sonoff.tech/ihost-user-guides/api/\n- https://www.npmjs.com/package/node-red-contrib-ewelink-cube\n",
"bugtrack_url": null,
"license": "",
"summary": "SONOFF eWelink CUBE API communication library (unofficial)",
"version": "0.0.2",
"project_urls": {
"Bug Tracker": "https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api/issues",
"Documentation": "https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api",
"Homepage": "https://github.com/sm4rth0m3/python-pip.sonoff-ewelink-cube-client-api"
},
"split_keywords": [
"sonoff",
"ewelink",
"cube",
"api",
"openapi",
"ihost",
"nspanel",
"library",
"asyncio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a102a20defe790300e5ee8c1d899eac2d3a4b8b9ff96ed6e3559368763862d1",
"md5": "3b55bf5137cb81f68567cfe4ea6df433",
"sha256": "92f74b67df7af7817a1ff2c5f30bf3a652b59e9038d6c12a8e9ac41ef813af90"
},
"downloads": -1,
"filename": "sonoff_ewelink_cube_client_api-0.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3b55bf5137cb81f68567cfe4ea6df433",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 23565,
"upload_time": "2023-05-29T22:08:30",
"upload_time_iso_8601": "2023-05-29T22:08:30.322706Z",
"url": "https://files.pythonhosted.org/packages/4a/10/2a20defe790300e5ee8c1d899eac2d3a4b8b9ff96ed6e3559368763862d1/sonoff_ewelink_cube_client_api-0.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "27c0deea46ed62c07b0f6e8804ac6b76499ff1a132005f68325e24ca94698e2f",
"md5": "b9c18578f8f9ffb4eb620e6ee5b4bb01",
"sha256": "09632a3f7f60a479396b25e8f06b4d13c4b6b840baddb997f9a80e72aa1f2fcb"
},
"downloads": -1,
"filename": "sonoff-ewelink-cube-client-api-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "b9c18578f8f9ffb4eb620e6ee5b4bb01",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 17789,
"upload_time": "2023-05-29T22:08:32",
"upload_time_iso_8601": "2023-05-29T22:08:32.867610Z",
"url": "https://files.pythonhosted.org/packages/27/c0/deea46ed62c07b0f6e8804ac6b76499ff1a132005f68325e24ca94698e2f/sonoff-ewelink-cube-client-api-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-29 22:08:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sm4rth0m3",
"github_project": "python-pip.sonoff-ewelink-cube-client-api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sonoff-ewelink-cube-client-api"
}