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.7.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

klyqa-1.0.7-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klyqa-1.0.7.tar.gz
  • Upload date:
  • Size: 10.4 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.7.tar.gz
Algorithm Hash digest
SHA256 55e12a5f1d520ec8841a6d03dd29aa14e363d25c6c88c2f5fdf61f81b611b127
MD5 879c551f35bafe4f9ff7f7da2a9e8f24
BLAKE2b-256 71d3a00442111448ca68e935a2838f514bfebe552b528a2bde7a32976f03ef9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klyqa-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.3 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1d98c0c4a520e5d57b2b7d9ca7ef796fbfe7d26c69ca52c73204df5d0d579320
MD5 069c23e82a2ceed9da48a34b0b621ef1
BLAKE2b-256 ed6d2abd442dd76fbb2aceb999a625736e88bd9c23dc0f44d91d648afc36b5a8

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