Skip to main content

Ketra Lighting API

Project description

aioketraapi

aiohttp-based Python Client SDK for controlling Ketra lighting products. Based on Ketra API documentation available here.

This Python package is automatically generated by the OpenAPI Generator project:

  • API version: 1.4.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.PythonClientCodegen

Requirements.

Python 3.6+

Installation & Usage

pip install

You can install from pypi using:

pip install aioketraapi

Or, you can install directly from github using:

pip install git+https://github.com/s4v4g3/aio-ketra-api.git

Note that in either case you may need to run pip with root permission: sudo pip install aioketraapi or sudo pip install git+https://github.com/s4v4g3/aio-ketra-api.git

Then import the package:

import aioketraapi

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import aioketraapi

Getting Started

In order to use this package you will need to contact Ketra Support and get assigned a client_id and client_secret.

Authentication

You will only need to obtain a single access token for a given user account; at present the access tokens do not expire.

import asyncio
from aioketraapi.oauth import OAuthTokenResponse

async def main():

    client_id = 'YOUR CLIENT ID'
    client_secret = 'YOUR CLIENT SECRET'
    username = '<your Ketra Design Studio username here>'
    password = '<your Ketra Design Studio password here>'

    oauth_token = await OAuthTokenResponse.request_token(client_id, client_secret, username, password)
    access_token = oauth_token.access_token
    print(f"My access token is {access_token}")

if __name__ == '__main__':
    asyncio.run(main())

Usage

import asyncio
from aioketraapi.n4_hub import N4Hub
from aioketraapi.models.lamp_state import LampState

async def main():

    # Find the installation id for your installation by logging into https://my.goketra.com
    # and finding your installation in the list and going to the “Details” page for your
    # installation. The installation id is displayed in the URL of this page, for example
    # a URL of https://my.goketra.com/installations/0fbcada7-b318-4d29-858c1ea3ac1fd5cb
    # would indicate an installation id of “0fbcada7-b318-4d29-858c1ea3ac1fd5cb”
    installation_id = 'my-installation-id'

    # Use the access token received from the authentication step above
    access_token = 'access token received from authentication step'

    # Set to False to access your installation directly through your local network,
    # set to True to access your installation through the cloud (requires remote access
    # to be enabled in Design Studio for the installation)
    use_cloud = False
    hub = await N4Hub.get_hub(installation_id,
                              access_token,
                              use_cloud=use_cloud)

    # get the keypads in the installation and print all button names
    keypads = await hub.get_keypads()
    for keypad in keypads:
        for button in keypad.buttons:
            print(button.scene_name)
            # activate the "Natural" button on the "Kitchen" keypad
            if button.scene_name == "Kitchen Natural":
                await button.activate()

    # get the groups in the installation and print all group names
    groups = await hub.get_groups()
    for group in groups:
        print(group.name)
        # Control the "Office" group
        if group.name == "Office":
            await group.set_state(LampState(transition_time=13000, cct=2000, brightness=0.95, power_on=True))


if __name__ == '__main__':
    asyncio.run(main())

License

The library is available as open source under the terms of the MIT License.

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

aioketraapi-0.1.12.tar.gz (55.7 kB view hashes)

Uploaded Source

Built Distribution

aioketraapi-0.1.12-py3-none-any.whl (103.6 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