Skip to main content

klyqa

klyqa is a Python library for interacting with Klyqa REST-enabled devices. It allows users to manage and control Klyqa smart devices, such as smart bulbs, by interfacing with the Klyqa cloud and directly with devices on the local network.

Installation

You can install the library directly from the source:

pip install klyqa

Requirements

  • Python 3.12+
  • zeroconf
  • aiohttp
  • orjson
  • mashumaro

Features

  • Connect to the Klyqa Cloud to manage devices.
  • Fetch device details such as name and access token.
  • Control device state (turn on/off, adjust color, brightness, etc.).
  • Fetch device information (e.g., firmware version, mode, etc.).

Usage

1. Interacting with the Klyqa Cloud

The library provides functionality to log in to the Klyqa Cloud and retrieve device details:

import asyncio
from klyqa.cloud import KlyqaCloud

async def cloud_interaction():
    # Login to the Klyqa Cloud
    cloud = KlyqaCloud("email@example.com", "your_password")
    await cloud.login()

    # Fetch devices from the cloud
    devices = await cloud.get_devices()
    print("Devices:", devices)

    # Get access token for a device
    local_device_id = "012345678901"
    access_token = await cloud.get_device_access_token(local_device_id)
    print("Access Token:", access_token)

    await cloud.close()

asyncio.run(cloud_interaction())

2. Controlling a Local Device

Once you have the access token from the cloud, you can control a device on the local network:

import asyncio
from aiohttp.client import ClientSession
from klyqa.device import KlyqaDevice
from klyqa.models import RGBColor

async def control_device():
    # Device connection details
    local_device_id = "012345678901"
    device_ip = "192.168.1.100"
    port = 3333

    # Use the access token fetched from the cloud
    access_token = "your_access_token"

    async with ClientSession() as session:
        # Connect to the local device
        device = KlyqaDevice(device_ip, port, access_token, session)

        # Turn the device on, set to blue color, and full brightness
        await device.light(on=True, color=RGBColor(red=0, green=0, blue=255), brightness=100)

        await device.close()

asyncio.run(control_device())

3. Fetching Device Info and State

You can also retrieve information about the device, such as its firmware version and current state:

import asyncio
from aiohttp.client import ClientSession
from klyqa.device import KlyqaDevice
from klyqa.models import Info, State

async def fetch_device_info():
    local_device_id = "012345678901"
    device_ip = "192.168.1.100"
    port = 3333
    access_token = "your_access_token"

    async with ClientSession() as session:
        device = KlyqaDevice(device_ip, port, access_token, session)

        # Get device info
        info: Info = await device.info()
        print("Device Info:", info)

        # Get device state
        state: State = await device.state()
        print("Device State:", state)

        await device.close()

asyncio.run(fetch_device_info())

Contributing

Bug reports and pull requests are welcome on GitHub at python-klyqa GitHub issues.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

MIT License

Copyright (c) 2024 ninharp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for klyqa 1.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for klyqa 1.0.10
File Size Uploaded Provenance Actions
klyqa-1.0.10.tar.gz 10.5 kB Without provenance Details for klyqa-1.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for klyqa 1.0.10
File Interpreter ABI Platform Actions
klyqa-1.0.10-py3-none-any.whl Python 3 none any Details for klyqa-1.0.10-py3-none-any.whl

Total release size: 20.9 kB

Release files / klyqa-1.0.10.tar.gz

Download URL klyqa-1.0.10.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
021e848cdbf947bb72de295430cb47fa51c03bc0f7342894c5ee391ef75226e9
BLAKE2b-256 checksum
How to use checksums
101067c401d7e7b463cf2fa9472bf1fe77b4db53c47111e96dbb96d0f00ab298
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Release files / klyqa-1.0.10-py3-none-any.whl

Download URL klyqa-1.0.10-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3ba522cb7b09d953bcb0ddb3e06cde4ceb41f2145c3d342c9dd79ae75190140
BLAKE2b-256 checksum
How to use checksums
854cb41eeabf99aaca31d281a4cfe7f12d17d63c2bad1820d41ede5fc87271f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Security for klyqa 1.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page