Package: aioketraapi
aioketraapiaiohttp-based Python Client SDK for controlling Ketra lighting products.   Based on Ketra API documentation availablehere.This Python package is automatically generated by theOpenAPI Generatorproject:API version: 1.4.0Package version: 1.0.0Build package: org.openapitools.codegen.languages.PythonClientCodegenRequirements.Python 3.6+Installation & Usagepip installYou can install from pypi using:pipinstallaioketraapiOr, you can install directly from github using:pipinstallgit+https://github.com/s4v4g3/aio-ketra-api.gitNote that in either case you may need to runpipwith root permission:sudo pip install aioketraapiorsudo pip install git+https://github.com/s4v4g3/aio-ketra-api.gitThen import the package:importaioketraapiSetuptoolsInstall viaSetuptools.pythonsetup.pyinstall--user(orsudo python setup.py installto install the package for all users)Then import the package:importaioketraapiGetting StartedIn order to use this package you will need to contact Ketra Support and get assigned a client_id and client_secret.AuthenticationYou will only need to obtain a single access token for a given user account; at present the access tokens do not expire.importasynciofromaioketraapi.oauthimportOAuthTokenResponseasyncdefmain():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=awaitOAuthTokenResponse.request_token(client_id,client_secret,username,password)access_token=oauth_token.access_tokenprint(f"My access token is{access_token}")if__name__=='__main__':asyncio.run(main())Usageimportasynciofromaioketraapi.n4_hubimportN4Hubfromaioketraapi.models.lamp_stateimportLampStateasyncdefmain():# 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 aboveaccess_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=Falsehub=awaitN4Hub.get_hub(installation_id,access_token,use_cloud=use_cloud)# get the keypads in the installation and print all button nameskeypads=awaithub.get_keypads()forkeypadinkeypads:forbuttoninkeypad.buttons:print(button.scene_name)# activate the "Natural" button on the "Kitchen" keypadifbutton.scene_name=="Kitchen Natural":awaitbutton.activate()# get the groups in the installation and print all group namesgroups=awaithub.get_groups()forgroupingroups:print(group.name)# Control the "Office" groupifgroup.name=="Office":awaitgroup.set_state(LampState(transition_time=13000,cct=2000,brightness=0.95,power_on=True))if__name__=='__main__':asyncio.run(main())LicenseThe library is available as open source under the terms of theMIT License.