Skip to main content

Hyperion Ambient Lighting Python Package

Project description

Build Status

Hyperion Library

Python library for Hyperion-NG. See JSON API for more details about the inputs and outputs of this library.

Usage

Client API calls

All API calls can be found in client.py. All async calls start with async_.

Calls

Note that the command and subcommand keys shown in the above documentation will automatically be included in the calls the client sends, and do not need to be specified.

Client inputs / outputs

The API parameters and output are all as defined in the JSON API documentation.

Example usage:

#!/usr/bin/python

import asyncio
from hyperion import client, const

HOST = "hyperion"

async def print_brightness():
    hyperion_client = client.HyperionClient(HOST)
    if not await hyperion_client.async_connect():
        return
    print("Brightness: %i%%" % hyperion_client.adjustment[0][const.KEY_BRIGHTNESS])

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(print_brightness())

Running in the background

The HyperionClient subscribes to updates from the Hyperion server, which are used to keep the client state fresh. Optionally, callbacks can be triggered to the user. To receive these callbacks, the client needs to run as an asyncio background task.

Callbacks

The client can be configured to callback as the Hyperion server reports new values. There are two classes of callbacks supported:

  • default_callback: This callback will be called when a more specific callback is not specified.
  • callbacks: A dict of callbacks keyed on the Hyperion subscription 'command' (see JSON API documentation)

Callbacks can be specified in the HyperionClient constructor (default_callback= or callbacks= arguments) or after construction via the set_callbacks() and set_default_callback() methods.

As above, the callbacks dict is keyed on the relevant Hyperion subscription command (e.g. components-update, priorities-update). The client also provides a custom callback with command connection-update of the following form:

{"command": "connection-update",
 "connected": True}

This can be used to take special action as the client connects or disconnects from the server.

Example use of asyncio event loop to deliver callbacks

from hyperion import client, const

HOST = "hyperion"

def callback(json):
    print("Received Hyperion command: %s" % json)

if __name__ == "__main__":
    hyperion_client = client.HyperionClient(HOST, default_callback=callback)
    asyncio.get_event_loop().run_until_complete(hyperion_client.async_connect())

    # Start client in "background".
    hyperion_client.start_background_task()
    asyncio.get_event_loop().run_forever()

Output:

Received Hyperion command: {'command': 'connection-update', 'connected': True}

ThreadedHyperionClient

A ThreadedHyperionClient is also provided as a convenience wrapper to for non-async code. The ThreadedHyperionClient wraps the async calls with non-async versions (without the async_ on the method names shown above).

Example use of Threaded client

#!/usr/bin/python

from hyperion import client, const

HOST = "hyperion"

def callback(json):
    print("Received Hyperion command: %s" % json)

if __name__ == "__main__":
    hyperion_client = client.ThreadedHyperionClient(HOST, default_callback=callback)

    hyperion_client.connect()
    print("Brightness: %i%%" % hyperion_client.adjustment[0][const.KEY_BRIGHTNESS])

    # Run in a separate thread.
    hyperion_client.start()
    hyperion_client.join()

Output:

Received Hyperion command: {'command': 'connection-update', 'connected': True}
Brightness: 59%

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

hyperion-py-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

hyperion_py-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file hyperion-py-0.1.0.tar.gz.

File metadata

  • Download URL: hyperion-py-0.1.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.7.5

File hashes

Hashes for hyperion-py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a5bb9ae14e58c894a50d07eeb4c6d5b16a82b740be0251d636a5115725af2be9
MD5 e43c7e530f1d4a522a556a504ff56c3d
BLAKE2b-256 e881a3346077ecf1504635b42e50ae16d2bfd875e2fd32db6c707079df37d1ee

See more details on using hashes here.

File details

Details for the file hyperion_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hyperion_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.8.0 tqdm/4.48.2 CPython/3.7.5

File hashes

Hashes for hyperion_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73d48eb807ef2527a03c5e1c9b7f7273e4daf8b6eaf51e75fe9d3cd80452bd67
MD5 907f42404082f3ab98a43379890f7813
BLAKE2b-256 1c7b637da8d4196a6b237bc902ae8d565e2144915a756680dca77ffe94dc8691

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