Skip to main content

Connection Library for Klyqa REST enabled devices

Project description

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.

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

klyqa-1.0.6.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

klyqa-1.0.6-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file klyqa-1.0.6.tar.gz.

File metadata

  • Download URL: klyqa-1.0.6.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for klyqa-1.0.6.tar.gz
Algorithm Hash digest
SHA256 ca01179a8636bc942da52a56357b85a9b430d5e3feb5b26d2d1c180bbac94157
MD5 47869f4121a5204fe376acac00e6c103
BLAKE2b-256 d70b1b8d5a5187cbcab389f59947c935f76668e1095928c26d9122279ccbabca

See more details on using hashes here.

File details

Details for the file klyqa-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: klyqa-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for klyqa-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a8da70d6968cb8ddd769da9edc1a98700bf28da4ffad2938d99500d106f5a9b9
MD5 9a4ff5d50b162cfc371bd4a3fda89786
BLAKE2b-256 cedbf88a65f5efa23cb8e5a7d66cbc5488ef7a693a3097b06e51551bd273ef35

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