Skip to main content

Electra Smart Python Integration.

Project description

pyElectra

PyPI PyPI - Downloads

Python library to control Electra Smart Air Condtioiner devices

Usage:

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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyElectra-1.2.4-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file pyElectra-1.2.4-py3-none-any.whl.

File metadata

  • Download URL: pyElectra-1.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pyElectra-1.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bb919466f816cee0a64905214aa45c5c3696271d4ca549e79fae678bc542dc11
MD5 83764d4166f38e7ce6e231a51726673d
BLAKE2b-256 9d33a2ba5f72e4625ee24def11056af7c5a7bda397ce29df3cd6398e20b7245e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page