palazzem / econnect-python

API adapter used to control programmatically an Elmo alarm system
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

Implement a check to return the status of the system #36

Closed palazzem closed 4 years ago

palazzem commented 4 years ago

Overview

At the moment is not possible to retrieve the status of the system, that is important to have a read capability on the system. ElmoClientshould:

palazzem commented 4 years ago

Available APIs

Scraping

Unfortunately APIs don't provide the name of the area or the item in alerted state. To grab the actual name, we can use beautifulsoup4 and do scraping on main pages:

Extraction:

from bs4 import BeautifulSoup

page = client._session.get("https://connect.elmospa.com/vendor/Areas")  # or Inputs
tree = BeautifulSoup(page.text, "html.parser")
rows = tree.select('tbody > tr')
areas = [x.getText().split('\n')[1] for x in rows]

# Output: ['Entryway', 'Kitchen', 'Bathroom', 'Something', 'Perimeter']
# Output: ['Door', 'Window']

Usage

status = client.check()
print(status)

# Output:
{
"areas_armed": [{"id": 0, "name": "Entryway"}, ...],
"areas_disarmed": [{"id": 1, "name": "Kitchen"}, ...],
"inputs_alerted": [{"id": 0, "name": "Door"}, ...],
"inputs_wait": [{"id": 1, "name": "Window"}, ...],
}