A simple Python 3 library for Notion Home Monitoring
Project description
📟 aionotion: a Python3, asyncio-friendly library for Notion® Home Monitoring
aionotion
is a Python 3, asyncio-friendly library for interacting with Notion
home monitoring sensors.
Installation
pip install aionotion
Python Versions
aionotion
is currently supported on:
- Python 3.9
- Python 3.10
- Python 3.11
Usage
import asyncio
from aiohttp import ClientSession
from aionotion import async_get_client
async def main() -> None:
"""Create the aiohttp session and run the example."""
client = await async_get_client("<EMAIL>", "<PASSWORD>", session=session)
# Get all "households" associated with the account:
systems = await client.system.async_all()
# Get a system by ID:
system = await client.system.async_get(12345)
# Create a system (with associated parameters):
await client.system.async_create({"system_id": 12345, "name": "Test"})
# Update a system with new parameters:
await client.system.async_update(12345, {"name": "Test"})
# Delete a system by ID:
await client.system.async_delete(12345)
# Get all bridges associated with the account:
bridges = await client.bridge.async_all()
# Get a bridge by ID:
bridge = await client.bridge.async_get(12345)
# Create a bridge (with associated parameters):
await client.bridge.async_create({"system_id": 12345, "name": "Test"})
# Update a bridge with new parameters:
await client.bridge.async_update(12345, {"name": "Test"})
# Reset a bridge (deprovision its WiFi credentials):
await client.bridge.async_reset(12345)
# Delete a bridge by ID:
await client.bridge.async_delete(12345)
# Get all devices associated with the account:
devices = await client.device.async_all()
# Get a device by ID:
device = await client.device.async_get(12345)
# Create a device (with associated parameters):
await client.device.async_create({"id": 12345})
# Delete a device by ID:
await client.device.async_delete(12345)
# Get all sensors:
sensors = await client.sensor.async_all()
# Get a sensor by ID:
sensor = await client.sensor.async_get(12345)
# Get "listeners" (conditions that a sensor is monitoring) for all sensors:
all_listeners = await client.sensor.async_listeners()
# Get "listeners" (conditions that a sensor is monitoring) for a specific sensor;
# note that unlike other sensor endpoints, this one requires the sensor UUID, *not*
# the sensor ID:
listeners_for_sensor = await client.sensor.async_listeners_for_sensor(
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
)
# Create a sensor (with associated parameters):
await client.sensor.async_create({"sensor_id": 12345, "name": "Test"})
# Update a sensor with new parameters:
await client.sensor.async_update(12345, {"name": "Test"})
# Delete a sensor by ID:
await client.sensor.async_delete(12345)
asyncio.run(main())
By default, the library creates a new connection to Notion with each coroutine. If you
are calling a large number of coroutines (or merely want to squeeze out every second of
runtime savings possible), an aiohttp
ClientSession
can be used for
connection pooling:
import asyncio
from aiohttp import ClientSession
from aionotion import async_get_client
async def main() -> None:
"""Create the aiohttp session and run the example."""
async with ClientSession() as session:
# Create a Notion API client:
client = await async_get_client("<EMAIL>", "<PASSWORD>", session=session)
# Get to work...
asyncio.run(main())
Check out the examples, the tests, and the source files themselves for method signatures and more examples.
Contributing
Thanks to all of our contributors so far!
- Check for open features/bugs or initiate a discussion on one.
- Fork the repository.
- (optional, but highly recommended) Create a virtual environment:
python3 -m venv .venv
- (optional, but highly recommended) Enter the virtual environment:
source ./.venv/bin/activate
- Install the dev environment:
script/setup
- Code your new feature or bug fix on a new branch.
- Write tests that cover your new functionality.
- Run tests and ensure 100% code coverage:
poetry run pytest --cov aionotion tests
- Update
README.md
with any new documentation. - Submit a pull request!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aionotion-2023.5.0.tar.gz
(11.9 kB
view hashes)
Built Distribution
Close
Hashes for aionotion-2023.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3994cfcb745baaf7adb1022b76ebbde4c2bb620f1ca80e846377c3cf83a03312 |
|
MD5 | e1d7ef5e3844c2b034f4631f6baab037 |
|
BLAKE2b-256 | 560727d3c8bde4f6c9cab24b1d0f8cf2b334430cb8081dc6acf433630553377a |