Skip to main content

HID-IO Python Library

Project description

hidio Client Python Library

HID-IO Client Side Library for Python

Linux Status macOS Status Windows Status

Visit our IRC channel

Getting

pip install hidio

Overview

This is a convenience Python library for the HID-IO daemon which handles automatic reconnection if the server goes down for any reason. The library also handles the HID-IO authentication procedure (key negotiation and TLS wrapping).

Usage

import asyncio
import sys

import hidio.client

# Optional callbacks
class MyHIDIOClient(hidio.client.HIDIOClient):
    async def on_connect(self, cap):
        print("Connected!")
        print("Connected API Call", await cap.alive().a_wait())


    async def on_disconnect(self):
        print("Disconnected!")


async def main():
    client = MyHIDIOClient('Python example.py')
    # Connect the client to the server using a background task
    # This will automatically reconnect
    tasks = [asyncio.gather(*[client.connect(auth=hidio.client.HIDIOClient.AUTH_BASIC)], return_exceptions=True)]
    while client.retry_connection_status():
        if client.capability_hidioserver():
            try:
                print("API Call", await asyncio.wait_for(
                    client.capability_hidioserver().alive().a_wait(),
                    timeout=2.0
                ))
                print("API Call", await asyncio.wait_for(
                    client.capability_authenticated().nodes().a_wait(),
                    timeout=2.0
                ))
            except asyncio.TimeoutError:
                print("Alive timeout.")
                continue
        await asyncio.sleep(5)


try:
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
except KeyboardInterrupt:
    print("Ctrl+C detected, exiting...")
    sys.exit(1)

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

hidio-0.1.0b1.tar.gz (11.3 kB view hashes)

Uploaded Source

Built Distribution

hidio-0.1.0b1-py3-none-any.whl (28.2 kB view hashes)

Uploaded Python 3

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