# aioremootio - An asynchronous API client library for Remootio
_aioremootio_ is an asynchronous API client library for [Remootio](https://remootio.com/) written in Python 3 and
based on [asyncio](https://docs.python.org/3/library/asyncio.html) and [aiohttp](https://pypi.org/project/aiohttp/).
## Supported functionalities of the device
With this client library is currently possible to listen to state changes of a [Remootio](https://remootio.com/) device,
to listen to some events triggered by it, furthermore to operate the gate or garage door connected to it.
This client library supports currently the listening to following kind of events triggered by the device:
* `STATE_CHANGE` which is triggered by the device when its state changes
* `RELAY_TRIGGER` which is triggered by the device when its control output has been triggered to operate the
connected gate or garage door
* `LEFT_OPEN` which is triggered by the device when the connected gate or garage door has been left open
* `RESTART` which is triggered by the device when it was restarted
## Using the library
The following example demonstrates how you can use this library.
```python
from typing import NoReturn
import logging
import asyncio
import aiohttp
import aioremootio
class ExampleStateListener(aioremootio.Listener[aioremootio.StateChange]):
__logger: logging.Logger
def __init__(self, logger: logging.Logger):
self.__logger = logger
async def execute(self, client: aioremootio.RemootioClient, subject: aioremootio.StateChange) -> NoReturn:
self.__logger.info("State of the device has been changed. Host [%s] OldState [%s] NewState [%s]" %
(client.host, subject.old_state, subject.new_state))
async def main() -> NoReturn:
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler: logging.Handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter(fmt="%(asctime)s [%(levelname)s] %(message)s"))
logger.addHandler(handler)
connection_options: aioremootio.ConnectionOptions = \
aioremootio.ConnectionOptions("192.168.0.1", "API_SECRET_KEY", "API_AUTH_KEY")
state_change_listener: aioremootio.Listener[aioremootio.StateChange] = ExampleStateListener(logger)
remootio_client: aioremootio.RemootioClient
async with aiohttp.ClientSession() as client_session:
try:
remootio_client = await aioremootio.RemootioClient(
connection_options,
client_session,
aioremootio.LoggerConfiguration(logger=logger),
[state_change_listener]
)
except aioremootio.RemootioClientConnectionEstablishmentError:
logger.exception("The client has failed to establish connection to the Remootio device.")
except aioremootio.RemootioClientAuthenticationError:
logger.exception("The client has failed to authenticate with the Remootio device.")
except aioremootio.RemootioError:
logger.exception("Failed to create client because of an error.")
else:
logger.info("State of the device: %s", remootio_client.state)
if remootio_client.state == aioremootio.State.NO_SENSOR_INSTALLED:
await remootio_client.trigger()
else:
await remootio_client.trigger_open()
await remootio_client.trigger_close()
while True:
await asyncio.sleep(0.1)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
```
To get the _API Secret Key_ and _API Auth Key_ of your [Remootio](https://remootio.com/) device you must enable the
API on it according to the
[Remootio Websocket API documentation](https://github.com/remootio/remootio-api-documentation).
## Running the bundled examples
The [project source](https://github.com/ivgg-me/aioremootio) does also contain two examples.
The example [`example.py`](https://github.com/ivgg-me/aioremootio/blob/master/example.py) demonstrates how you can
use the client as a Python object.
The example [`example_mc.py`](https://github.com/ivgg-me/aioremootio/blob/master/example_mc.py) demonstrates how you can
use the client as a Python object where it does not establish a connection to the Remootio device automatically
during its initialization.
The example [`example_acm.py`](https://github.com/ivgg-me/aioremootio/blob/master/example_acm.py) demonstrates how
you can use the client as an asynchronous context manager.
To run the bundled examples you must
1. also enable the API on your [Remootio](https://remootio.com/) device to get the _API Secret Key_ and _API Auth
Key_ of it, and
2. add the source folder [`/src`](https://github.com/ivgg-me/aioremootio/tree/master/src) of the repository to your
`PYTHONPATH`.
After the two steps described above you can run the bundled examples with the argument `--help` to show
the usage information. E.g.:
```commandline
python example.py --help
```
## Running the bundled tests
To run the bundled tests you must create the `.\remootio_device.configuration.json` file with a content according
to the following template.
```
{
"host": "IP-ADDRESS-OR-HOST-NAME-OF-YOUR-DEVICE",
"api_secret_key": "API-SECRET-KEY-OF-YOUR-DEVICE",
"api_auth_key": "API-AUTH-KEY-OF-YOUR-DEVICE",
"api_version": API-VERSION-OF-YOUR-DEVICE
}
```
---
Copyright © 2021 Gergö Gabor Ilyes-Veisz.
Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
<a href="https://www.buymeacoffee.com/ivgg" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-blue.png" alt="Buy Me A Coffee" height="41" width="174"></a>
Raw data
{
"_id": null,
"home_page": "https://github.com/ivgg-me/aioremootio",
"name": "aioremootio",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "remootio,client,library,asynchronous",
"author": "Gerg\u00f6 Gabor Ilyes-Veisz",
"author_email": "i@ivgg.me",
"download_url": "https://files.pythonhosted.org/packages/5f/3c/0038bf58451c35c5a8e78e32fc125891260c6b940c9f80dd1145200c0c06/aioremootio-1.0.0a21.tar.gz",
"platform": null,
"description": "# aioremootio - An asynchronous API client library for Remootio\n\n_aioremootio_ is an asynchronous API client library for [Remootio](https://remootio.com/) written in Python 3 and \nbased on [asyncio](https://docs.python.org/3/library/asyncio.html) and [aiohttp](https://pypi.org/project/aiohttp/).\n\n## Supported functionalities of the device\n\nWith this client library is currently possible to listen to state changes of a [Remootio](https://remootio.com/) device, \nto listen to some events triggered by it, furthermore to operate the gate or garage door connected to it.\n\nThis client library supports currently the listening to following kind of events triggered by the device:\n* `STATE_CHANGE` which is triggered by the device when its state changes\n* `RELAY_TRIGGER` which is triggered by the device when its control output has been triggered to operate the \n connected gate or garage door\n* `LEFT_OPEN` which is triggered by the device when the connected gate or garage door has been left open\n* `RESTART` which is triggered by the device when it was restarted\n\n## Using the library\n\nThe following example demonstrates how you can use this library.\n\n```python\nfrom typing import NoReturn\nimport logging\nimport asyncio\nimport aiohttp\nimport aioremootio\n\n\nclass ExampleStateListener(aioremootio.Listener[aioremootio.StateChange]):\n __logger: logging.Logger\n\n def __init__(self, logger: logging.Logger):\n self.__logger = logger\n\n async def execute(self, client: aioremootio.RemootioClient, subject: aioremootio.StateChange) -> NoReturn:\n self.__logger.info(\"State of the device has been changed. Host [%s] OldState [%s] NewState [%s]\" %\n (client.host, subject.old_state, subject.new_state))\n\n\nasync def main() -> NoReturn:\n logger = logging.getLogger(__name__)\n logger.setLevel(logging.INFO)\n\n handler: logging.Handler = logging.StreamHandler()\n handler.setFormatter(logging.Formatter(fmt=\"%(asctime)s [%(levelname)s] %(message)s\"))\n logger.addHandler(handler)\n\n connection_options: aioremootio.ConnectionOptions = \\\n aioremootio.ConnectionOptions(\"192.168.0.1\", \"API_SECRET_KEY\", \"API_AUTH_KEY\")\n\n state_change_listener: aioremootio.Listener[aioremootio.StateChange] = ExampleStateListener(logger)\n\n remootio_client: aioremootio.RemootioClient\n \n async with aiohttp.ClientSession() as client_session:\n try:\n remootio_client = await aioremootio.RemootioClient(\n connection_options,\n client_session,\n aioremootio.LoggerConfiguration(logger=logger),\n [state_change_listener]\n )\n except aioremootio.RemootioClientConnectionEstablishmentError:\n logger.exception(\"The client has failed to establish connection to the Remootio device.\")\n except aioremootio.RemootioClientAuthenticationError:\n logger.exception(\"The client has failed to authenticate with the Remootio device.\")\n except aioremootio.RemootioError:\n logger.exception(\"Failed to create client because of an error.\")\n else:\n logger.info(\"State of the device: %s\", remootio_client.state)\n \n if remootio_client.state == aioremootio.State.NO_SENSOR_INSTALLED:\n await remootio_client.trigger()\n else:\n await remootio_client.trigger_open()\n await remootio_client.trigger_close()\n \n while True:\n await asyncio.sleep(0.1)\n\nif __name__ == \"__main__\":\n try:\n asyncio.run(main())\n except KeyboardInterrupt:\n pass\n```\n\nTo get the _API Secret Key_ and _API Auth Key_ of your [Remootio](https://remootio.com/) device you must enable the \nAPI on it according to the \n[Remootio Websocket API documentation](https://github.com/remootio/remootio-api-documentation). \n\n## Running the bundled examples\n\nThe [project source](https://github.com/ivgg-me/aioremootio) does also contain two examples.\n\nThe example [`example.py`](https://github.com/ivgg-me/aioremootio/blob/master/example.py) demonstrates how you can \nuse the client as a Python object.\n\nThe example [`example_mc.py`](https://github.com/ivgg-me/aioremootio/blob/master/example_mc.py) demonstrates how you can\nuse the client as a Python object where it does not establish a connection to the Remootio device automatically \nduring its initialization.\n\nThe example [`example_acm.py`](https://github.com/ivgg-me/aioremootio/blob/master/example_acm.py) demonstrates how \nyou can use the client as an asynchronous context manager.\n\nTo run the bundled examples you must \n1. also enable the API on your [Remootio](https://remootio.com/) device to get the _API Secret Key_ and _API Auth \n Key_ of it, and\n2. add the source folder [`/src`](https://github.com/ivgg-me/aioremootio/tree/master/src) of the repository to your \n `PYTHONPATH`.\n\nAfter the two steps described above you can run the bundled examples with the argument `--help` to show \nthe usage information. E.g.:\n\n```commandline\npython example.py --help\n```\n\n## Running the bundled tests\n\nTo run the bundled tests you must create the `.\\remootio_device.configuration.json` file with a content according \nto the following template.\n\n```\n{\n \"host\": \"IP-ADDRESS-OR-HOST-NAME-OF-YOUR-DEVICE\",\n \"api_secret_key\": \"API-SECRET-KEY-OF-YOUR-DEVICE\",\n \"api_auth_key\": \"API-AUTH-KEY-OF-YOUR-DEVICE\",\n \"api_version\": API-VERSION-OF-YOUR-DEVICE\n}\n```\n\n---\n\nCopyright © 2021 Gerg\u00f6 Gabor Ilyes-Veisz. \nLicensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\n<a href=\"https://www.buymeacoffee.com/ivgg\" target=\"_blank\"><img src=\"https://cdn.buymeacoffee.com/buttons/default-blue.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"></a>\n\n",
"bugtrack_url": null,
"license": "",
"summary": "An asynchronous API client library for Remootio (http://www.remootio.com/)",
"version": "1.0.0a21",
"project_urls": {
"Bug Tracker": "https://github.com/ivgg-me/aioremootio/issues",
"Homepage": "https://github.com/ivgg-me/aioremootio",
"Source": "https://github.com/ivgg-me/aioremootio/"
},
"split_keywords": [
"remootio",
"client",
"library",
"asynchronous"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "83ed9a9f8adb054a463c29e3bf0a52c51f42d2422ee6fcc85f439695421f5049",
"md5": "926f4f7be798fd1e276c743f157dbbc6",
"sha256": "3e88d3cc5b7f03dbf85c2f8b2f255124a1b2805275eeb2b25206368ccf7f8eaf"
},
"downloads": -1,
"filename": "aioremootio-1.0.0a21-py3-none-any.whl",
"has_sig": false,
"md5_digest": "926f4f7be798fd1e276c743f157dbbc6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 28613,
"upload_time": "2024-02-25T10:03:02",
"upload_time_iso_8601": "2024-02-25T10:03:02.949079Z",
"url": "https://files.pythonhosted.org/packages/83/ed/9a9f8adb054a463c29e3bf0a52c51f42d2422ee6fcc85f439695421f5049/aioremootio-1.0.0a21-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5f3c0038bf58451c35c5a8e78e32fc125891260c6b940c9f80dd1145200c0c06",
"md5": "7d03f66ee4c2fc95056c4a9d2e08ab79",
"sha256": "89bb6e6edf47006006033c888a1e835b2acf6bf15f650fb4611dc20cbe3370b7"
},
"downloads": -1,
"filename": "aioremootio-1.0.0a21.tar.gz",
"has_sig": false,
"md5_digest": "7d03f66ee4c2fc95056c4a9d2e08ab79",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 25693,
"upload_time": "2024-02-25T10:03:04",
"upload_time_iso_8601": "2024-02-25T10:03:04.910930Z",
"url": "https://files.pythonhosted.org/packages/5f/3c/0038bf58451c35c5a8e78e32fc125891260c6b940c9f80dd1145200c0c06/aioremootio-1.0.0a21.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-25 10:03:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ivgg-me",
"github_project": "aioremootio",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "aioremootio"
}