Skip to main content

API adapter used to control programmatically an Elmo alarm system.

Project description

E-connect Python API

PyPI version CircleCI codecov

econnect-python is an API adapter used to control programmatically an Elmo alarm system. Through a generic configuration, the client allows:

  • Retrieving access tokens to make API calls
  • Obtaining/releasing the system Lock() to have exclusive control of the system
  • Arm/disarm all the alarms registered in the system
  • Query the system and get the status of your sectors and inputs

Requirements

  • Python 3.6+
  • requests

Getting Started

This package is available on PyPI:

$ pip install econnect-python

Usage

from elmo import query
from elmo.api.client import ElmoClient

# Initialize a new client to authenticate your connection
# and retrieve an access token used for the entire session.
client = ElmoClient()
client.auth("username", "password")

# To arm/disarm the system you must gain the exclusive Lock()
with client.lock("secret-code") as c:
    c.arm()                # Arm all alarms
    c.disarm()             # Disarm all alarms
    c.arm(sectors=[3, 4])  # Arm only sectors 3 and 4
    c.disarm(sectors=[3])  # Disarm only sector 3

# Query the system
sectors_armed, sectors_disarmed = client.query(query.SECTORS)
inputs_alerted, inputs_wait = client.query(query.INPUTS)

# Or use the shortcut
status = client.check()

# Returns:
# {
#   "sectors_armed": [{"id": 0, "name": "Entryway", "element": 1, "index": 0}, ...],
#   "sectors_disarmed": [{"id": 1, "name": "Kitchen", "element": 2, "index": 1}, ...],
#   "inputs_alerted": [{"id": 0, "name": "Door", "element": 3, "index": 0}, ...],
#   "inputs_wait": [{"id": 1, "name": "Window", "element": 4, "index": 1}, ...],
# }

The access token is valid for 10 minutes, after which, you need to authenticate again to refresh the token. Obtaining the lock via client.lock("secret-code") is mandatory to arm or disarm the system, otherwise the API returns 403. secret-code is the numeric code you use to arm/disarm the system from the alarm panel.

Once the lock is obtained, other clients cannot connect to the alarm system and only a manual override on the terminal is allowed. Outside the context manager, the lock is automatically released.

Client Configuration

If https://connect.elmospa.com is your authentication page, no configuration is needed and you can skip this section.

On the other hand, if your authentication page is something similar to https://connect3.elmospa.com/nwd, you must configure your client as follows:

# Override the default URL and domain
client = ElmoClient(base_url="https://connect3.elmospa.com", domain="nwd")
client.auth("username", "password")

If your base_url or domain are not properly set, your credentials will not work and you will get a 403 Client Error as your username and password are wrong.

Development

We accept external contributions even though the project is mostly designed for personal needs. If you think some parts can be exposed with a more generic interface, feel free to open a GitHub issue and to discuss your suggestion.

Coding Guidelines

We use flake8 as a style guide enforcement. That said, we also use black to reformat our code, keeping a well defined style even for quotes, multi-lines blocks and other.

Before submitting your code, be sure to launch black to reformat your PR.

Testing

tox is used to execute the following test matrix:

  • lint: launches flake8 and black --check to be sure the code honors our style guideline
  • py{35,36,37,38}: launches py.test to execute all tests under Python 3.5, 3.6, 3.7 and 3.8.

To launch the full test matrix, just:

$ tox

Project details


Download files

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

Source Distribution

econnect-python-0.4.0.dev1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

econnect_python-0.4.0.dev1-py2.py3-none-any.whl (12.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file econnect-python-0.4.0.dev1.tar.gz.

File metadata

  • Download URL: econnect-python-0.4.0.dev1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for econnect-python-0.4.0.dev1.tar.gz
Algorithm Hash digest
SHA256 826c70754ce0007b28bda310a8bf5b590897238745f3dc168daf15b225ae8b20
MD5 c7ff4bcf6bfb343f54c1626ef4c2f619
BLAKE2b-256 5f34657a6638348fdb1cb5b11caa5389db0a76787afa03e9db0a9ccf1f5ac429

See more details on using hashes here.

File details

Details for the file econnect_python-0.4.0.dev1-py2.py3-none-any.whl.

File metadata

  • Download URL: econnect_python-0.4.0.dev1-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.0

File hashes

Hashes for econnect_python-0.4.0.dev1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 80a1fa66b31b907033511d9f4c05e713ac1e7461776646f246b2b05805d173e5
MD5 564d7e8842e563f226ef5be0b300e0da
BLAKE2b-256 0965f3dd3c4e9eaecc2f7a51d351e54f9bbb422e316db00878542b2a073892cb

See more details on using hashes here.

Supported by

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