Skip to content

Commit

Permalink
Merge pull request #11 from bachya/dev-update
Browse files Browse the repository at this point in the history
Update library to Python 3.5+ and asyncio
  • Loading branch information
arraylabs authored Nov 10, 2018
2 parents 7b16884 + 346670f commit 0ace49e
Show file tree
Hide file tree
Showing 13 changed files with 623 additions and 284 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.mypy_cache
Pipfile.lock
pymyq.egg-info
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
init:
pip install pip pipenv
pipenv lock
pipenv install --dev
lint:
pipenv run flake8 pymyq
pipenv run pydocstyle pymyq
pipenv run pylint pymyq
publish:
pipenv run python setup.py sdist bdist_wheel
pipenv run twine upload dist/*
rm -rf dist/ build/ .egg simplisafe_python.egg-info/
typing:
pipenv run mypy --ignore-missing-imports pymyq
15 changes: 15 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true

[dev-packages]
"flake8" = "*"
mypy = "*"
pydocstyle = "*"
pylint = "*"
twine = "*"

[packages]
aiodns = "*"
aiohttp = "*"
async-timeout = "*"
92 changes: 66 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,86 @@
# Introduction

This is a python module aiming to interact with the Chamberlain MyQ API.
This is a Python 3.5+ module aiming to interact with the Chamberlain MyQ API.

Code is licensed under the MIT license.

Getting Started
===============
# Getting Started

# Usage
## Installation

```python
from pymyq import MyQAPI as pymyq
pip install pymyq
```

## Usage

`pymyq` starts within an [aiohttp](https://aiohttp.readthedocs.io/en/stable/)
`ClientSession`:

```python
import asyncio

from aiohttp import ClientSession


async def main() -> None:
"""Create the aiohttp session and run."""
async with ClientSession() as websession:
# YOUR CODE HERE


myq = pymyq(username, password, brand)
asyncio.get_event_loop().run_until_complete(main())
```

# Methods
To get all MyQ devices associated with an account:

def is_supported_brand(self):
"""Return true/false based on supported brands list and input."""
```python
import asyncio

from aiohttp import ClientSession

import pymyq


async def main() -> None:
"""Create the aiohttp session and run."""
async with ClientSession() as websession:
# Valid Brands: 'chamberlain', 'craftsman', 'liftmaster', 'merlin'
myq = await pymyq.login('<EMAIL>', '<PASSWORD>', '<BRAND>', websession)

def is_login_valid(self):
"""Return true/false based on successful authentication."""
# Return only cover devices:
devices = await myq.get_devices()

# Return *all* devices:
devices = await myq.get_devices(covers_only=False)


asyncio.get_event_loop().run_until_complete(main())
```

def get_devices(self):
"""Return devices from API"""
## Device Properties

def get_garage_doors(self):
"""Parse devices data and extract garage doors. Return garage doors."""

def get_status(self, device_id):
"""Return current door status(open/closed)"""
* `brand`: the brand of the device
* `device_id`: the device's MyQ ID
* `parent_id`: the device's parent device's MyQ ID
* `name`: the name of the device
* `serial`: the serial number of the device
* `state`: the device's current state
* `type`: the type of MyQ device

def close_device(self, device_id):
"""Send request to close the door."""
## Methods

def open_device(self, device_id):
"""Send request to open the door."""
All of the routines on the `MyQDevice` class are coroutines and need to be
`await`ed.

def set_state(self, device_id, state):
"""Send request for request door state change."""
* `close`: close the device
* `open`: open the device
* `update`: get the latest device state (which can then be accessed via the
`state` property)

### Disclaimer
# Disclaimer

The code here is based off of an unsupported API from [Chamberlain](http://www.chamberlain.com/) and is subject to change without notice. The authors claim no responsibility for damages to your garage door or property by use of the code within.
The code here is based off of an unsupported API from
[Chamberlain](http://www.chamberlain.com/) and is subject to change without
notice. The authors claim no responsibility for damages to your garage door or
property by use of the code within.
39 changes: 39 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Run an example script to quickly test any MyQ account."""
import asyncio

from aiohttp import ClientSession

import pymyq
from pymyq.errors import MyQError


async def main() -> None:
"""Create the aiohttp session and run the example."""
async with ClientSession() as websession:
try:
myq = await pymyq.login(
'<EMAIL>', '<PASSWORD>', '<BRAND>', websession)

devices = await myq.get_devices()
for idx, device in enumerate(devices):
print('Device #{0}: {1}'.format(idx + 1, device.name))
print('--------')
print('Brand: {0}'.format(device.brand))
print('Type: {0}'.format(device.type))
print('Serial: {0}'.format(device.serial))
print('Device ID: {0}'.format(device.device_id))
print('Parent ID: {0}'.format(device.parent_id))
print('Current State: {0}'.format(device.state))
print()
print('Opening the device...')
await device.open()
print('Current State: {0}'.format(device.state))
await asyncio.sleep(15)
print('Closing the device...')
await device.close()
print('Current State: {0}'.format(device.state))
except MyQError as err:
print(err)


asyncio.get_event_loop().run_until_complete(main())
Loading

0 comments on commit 0ace49e

Please sign in to comment.