Skip to main content

Library for communicate with websc

Project description

WebSC client

Python Client for WebSC API. The control method is the same as for the LedSC library. After connecting to the WebSC server, the library provides access to all functions available using the control API.

Example:

import asyncio
import logging
import random

from websc_client import WebSClientAsync as WebSClient
from websc_client import WebSCAsync


async def on_device_change(data: dict[str, int]):
    # Display changed variables
    print(data)


async def run():
    # Connect to WebSC server
    client = WebSClient(host="127.0.0.1", port=8443)
    await client.connect()

    # Start observer for API listening
    observer = asyncio.create_task(client.observer())

    # Selects a device at random from the available devices.
    device: WebSCAsync = random.choice(list(client.devices.values()))

    # Registration for a device state change event
    device.set_callback(on_device_change)

    try:
        while True:
            # It changes colour randomly once every half a second
            await device.set_rgb(
                red=round(random.random() * 255),
                green=round(random.random() * 255),
                blue=round(random.random() * 255),
            )
            await asyncio.sleep(0.5)
    finally:
        observer.cancel()
        await client.disconnect()


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    try:
        asyncio.run(run())
    except KeyboardInterrupt:
        pass

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

websc_client-1.0.4.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

websc_client-1.0.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file websc_client-1.0.4.tar.gz.

File metadata

  • Download URL: websc_client-1.0.4.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for websc_client-1.0.4.tar.gz
Algorithm Hash digest
SHA256 690912dee1aebfd199df7b8d21512013286305802306a7521c62fafa6158a769
MD5 c2f17935c7d2cacaced0111f466ef3a5
BLAKE2b-256 1f6ff2c245fda4fddcbd7b52b484dc9cf62fa4c5fbca354adb6028e396280462

See more details on using hashes here.

File details

Details for the file websc_client-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: websc_client-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for websc_client-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a46d1765ecc8b04c3403204fb826a0cb4335496cf5a680913caeea49cfe702b7
MD5 83a0f8e44a314ac5d1b427817ada0256
BLAKE2b-256 cda6a39d3fbc2e58e75d0b9f53d1fc6ffb2fdf7bf2289fe612a6b88d6912c73d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page