# pyElectra
![PyPI](https://img.shields.io/pypi/v/pyelectra?label=pypi%20package)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pyelectra)
Python library to control Electra Smart Air Condtioiner devices
Usage:
```python
import asyncio
import aiohttp
from electrasmart import *
async def main():
session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False), timeout=aiohttp.ClientTimeout(total=10))
api = ElectraAPI(session)
# User phone number
phone_number = "0521234567"
# Generate token
imei = generate_imei()
try:
resp = await api.generate_new_token(phone_number=phone_number, imei=imei)
except ElectraApiError as e:
# handle error
pass
otp = input("Enter the OTP you recieved via SMS")
# more error handling
if resp[electra.ATTR_STATUS] == electra.STATUS_SUCCESS:
if resp[electra.ATTR_DATA][electra.ATTR_RES] != electra.STATUS_SUCCESS:
# Wrong phone number or unregistered user
sys.exit(1)
resp = await api.validate_one_time_password(otp=otp, imei=imei, phone_number=phone_number)
if resp[electra.ATTR_DATA][electra.ATTR_RES] == electra.STATUS_SUCCESS:
token = resp[electra.ATTR_DATA][electra.ATTR_TOKEN]
else:
# wrong OTP
sys.exit(1)
ac_devices = api.get_devices()
for ac in ac_devices:
assert(ac, ElectraAirConditioner)
if ac.name == "Saloon AC":
ac.turn_on()
ac.set_mode(OPER_MODE_COOL)
ac.set_temperature(17)
ac.set_fan_speed(OPER_FAN_SPEED_HIGH)
ac.set_vertical_swing(OPER_ON)
api.set_state(ac) # This will send the conf to the AC
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pyElectra",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "home, automation, Electra, smart, Electra Smart, Air Condition",
"author": null,
"author_email": "Jafar Atili <at.jafar@outlook.com>",
"download_url": null,
"platform": null,
"description": "# pyElectra\n\n![PyPI](https://img.shields.io/pypi/v/pyelectra?label=pypi%20package)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pyelectra)\n\nPython library to control Electra Smart Air Condtioiner devices\n\n\nUsage:\n\n```python\nimport asyncio\n\nimport aiohttp\n\nfrom electrasmart import *\n\n\nasync def main():\n session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False), timeout=aiohttp.ClientTimeout(total=10))\n api = ElectraAPI(session)\n\n # User phone number\n phone_number = \"0521234567\"\n # Generate token\n imei = generate_imei()\n try:\n resp = await api.generate_new_token(phone_number=phone_number, imei=imei)\n except ElectraApiError as e:\n # handle error\n pass\n\n otp = input(\"Enter the OTP you recieved via SMS\")\n # more error handling\n if resp[electra.ATTR_STATUS] == electra.STATUS_SUCCESS:\n if resp[electra.ATTR_DATA][electra.ATTR_RES] != electra.STATUS_SUCCESS:\n # Wrong phone number or unregistered user\n sys.exit(1)\n \n resp = await api.validate_one_time_password(otp=otp, imei=imei, phone_number=phone_number)\n if resp[electra.ATTR_DATA][electra.ATTR_RES] == electra.STATUS_SUCCESS:\n token = resp[electra.ATTR_DATA][electra.ATTR_TOKEN]\n else:\n # wrong OTP\n sys.exit(1)\n \n ac_devices = api.get_devices()\n for ac in ac_devices:\n assert(ac, ElectraAirConditioner)\n if ac.name == \"Saloon AC\":\n ac.turn_on()\n ac.set_mode(OPER_MODE_COOL)\n ac.set_temperature(17)\n ac.set_fan_speed(OPER_FAN_SPEED_HIGH)\n ac.set_vertical_swing(OPER_ON)\n api.set_state(ac) # This will send the conf to the AC\n\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(main())\n\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Electra Smart Python Integration.",
"version": "1.2.4",
"project_urls": {
"homepage": "https://pypi.org/project/pyelectra/",
"repository": "https://github.com/jafar-atili/pyelectra/"
},
"split_keywords": [
"home",
" automation",
" electra",
" smart",
" electra smart",
" air condition"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9d33a2ba5f72e4625ee24def11056af7c5a7bda397ce29df3cd6398e20b7245e",
"md5": "83764d4166f38e7ce6e231a51726673d",
"sha256": "bb919466f816cee0a64905214aa45c5c3696271d4ca549e79fae678bc542dc11"
},
"downloads": -1,
"filename": "pyElectra-1.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "83764d4166f38e7ce6e231a51726673d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 11145,
"upload_time": "2024-07-28T07:07:37",
"upload_time_iso_8601": "2024-07-28T07:07:37.039754Z",
"url": "https://files.pythonhosted.org/packages/9d/33/a2ba5f72e4625ee24def11056af7c5a7bda397ce29df3cd6398e20b7245e/pyElectra-1.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-28 07:07:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jafar-atili",
"github_project": "pyelectra",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyelectra"
}