Skip to main content

A simple Python 3 library for Notion Home Monitoring

Project description

📟 aionotion: a Python3, asyncio-friendly library for Notion® Home Monitoring

CI PyPi Version License Code Coverage Maintainability Say Thanks

aionotion is a Python 3, asyncio-friendly library for interacting with Notion home monitoring sensors.

Python Versions

aionotion is currently supported on:

  • Python 3.6
  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10

Installation

pip install aionotion

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)

    # 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)

    # Get all "tasks" (conditions monitored by sensors) associated with the account:
    tasks = await client.task.async_all()

    # Get a task by ID:
    task = await client.task.async_get("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")

    # Get a task's value history between two datetimes:
    import datetime

    history = await client.task.async_history(
        "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        data_before=datetime.datetime.now(),
        data_after=datetime.datetime.now() - datetime.timedelta(days=3),
    )

    # Create a list of tasks for a particular sensor (e.g., sensor # 12345):
    await client.task.async_create(
        12345, [{"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "type": "missing"}]
    )

    # Delete a task for a particular sensor (e.g., sensor # 12345):
    await client.task.async_delete(12345, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")


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

  1. Check for open features/bugs or initiate a discussion on one.
  2. Fork the repository.
  3. (optional, but highly recommended) Create a virtual environment: python3 -m venv .venv
  4. (optional, but highly recommended) Enter the virtual environment: source ./venv/bin/activate
  5. Install the dev environment: script/setup
  6. Code your new feature or bug fix.
  7. Write tests that cover your new functionality.
  8. Run tests and ensure 100% code coverage: script/test
  9. Update README.md with any new documentation.
  10. Add yourself to AUTHORS.md.
  11. Submit a pull request!

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

aionotion-2021.10.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aionotion-2021.10.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file aionotion-2021.10.0.tar.gz.

File metadata

  • Download URL: aionotion-2021.10.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.12 Linux/5.8.0-1042-azure

File hashes

Hashes for aionotion-2021.10.0.tar.gz
Algorithm Hash digest
SHA256 bb655107bc5120edb10e83f31cd40af35cea22cc47cc9259983ce7020ea3b3e5
MD5 5c5922b6ed09fa9b82fe273349fc3234
BLAKE2b-256 933ae9f2e82172d9f443dfb4049f4161d28b28758f6d0b8c550fa0322834e4e4

See more details on using hashes here.

File details

Details for the file aionotion-2021.10.0-py3-none-any.whl.

File metadata

  • Download URL: aionotion-2021.10.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.7.12 Linux/5.8.0-1042-azure

File hashes

Hashes for aionotion-2021.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f23a837ad59b96c98097e8c640d70b5daad7d245b72f7423640ad3a79f90361
MD5 19b3b0fb7525ed120baa4983d8442988
BLAKE2b-256 158bd46a90e9544d724d497c69c8325f40f76582cf6866340da3e1c414385828

See more details on using hashes here.

Supported by

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