Skip to main content

Asynchronous Python wrapper library over Bond Local API

Project description

bond-api

Asynchronous Python wrapper library over Bond Local API

Installation

From PyPi:

pip3 install bond-api

Library Usage

import asyncio

from aiohttp import ClientResponseError, ClientConnectorError

from bond_api import Bond, Action


async def main():
    """Example of library usage."""
    
    bond = Bond("[your ip or hostname here]", "[your bond API token here]")

    try:
        print("Version:")
        print(await bond.version())

        print("Device IDs:")
        device_ids = await bond.devices()
        print(device_ids)

        print("Devices:")
        devices = await asyncio.gather(*[bond.device(device_id) for device_id in device_ids])
        print(devices)

        print("Devices Properties:")
        properties = await asyncio.gather(*[bond.device_properties(device_id) for device_id in device_ids])
        print(properties)

        print("Devices State:")
        state = await asyncio.gather(*[bond.device_state(device_id) for device_id in device_ids])
        print(state)

        print("Turn on fan!")
        await bond.action("[your fan device ID here]", Action.turn_on())

        print("Change fan speed!")
        await bond.action("[your fan device ID here]", Action.set_speed(2))

        print("Turn off fan!")
        await bond.action("[your fan device ID here]", Action.turn_off())
        
    except ClientResponseError as x:
        print("Client response error: ", x)
    except ClientConnectorError as x:
        print("Client connector error: ", x)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

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

bond_api-0.1.18.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

bond_api-0.1.18-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file bond_api-0.1.18.tar.gz.

File metadata

  • Download URL: bond_api-0.1.18.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for bond_api-0.1.18.tar.gz
Algorithm Hash digest
SHA256 406f2ae4bba27e3695c0f0e7f4dab59f263e9ce50986b9fb49cac85de0cc8811
MD5 27a9775d6e84c9ccb87af61fb5d99fcf
BLAKE2b-256 fcb1b926a7b3eccea7749f91592b87209435c49471d4bcd148a4ce414986101b

See more details on using hashes here.

File details

Details for the file bond_api-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: bond_api-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for bond_api-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 dd60e96ad1b1aef98a3a6aa989c50470bef011829cf3e11a6770ce7a135c2c8e
MD5 05701d46ab262f89ee7b81f62e04013b
BLAKE2b-256 c6a72b3c086aa15b0bb523481054f31354e2ac3ab37f10d38d0cd1af4fa93937

See more details on using hashes here.

Supported by

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