Skip to content

Async Client

pypixelcolor.client.AsyncClient

Asynchronous client for controlling the LED matrix via BLE.

Source code in src/pypixelcolor/client.py
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
class AsyncClient:
    """Asynchronous client for controlling the LED matrix via BLE."""

    def __init__(self, address: str):
        """Initialize the AsyncClient.

        Args:
            address: Bluetooth device address (e.g., "1D:6B:5E:B5:A5:54")
        """
        self._session = DeviceSession(address)
        self._connected = False

    async def connect(self) -> None:
        """Connect to the BLE device and retrieve device info."""
        if self._connected:
            logger.warning("Already connected")
            return

        await self._session.connect()
        self._connected = True

    async def disconnect(self) -> None:
        """Disconnect from the BLE device."""
        if not self._connected:
            logger.warning("Not connected")
            return

        await self._session.disconnect()
        self._connected = False

    def version(self) -> str:
        """Get the client library version."""
        return VERSION

    def get_device_info(self) -> DeviceInfo:
        """
        Get cached device information.

        Device info is automatically retrieved during connect().
        This is a simple getter for the cached data.

        Returns:
            DeviceInfo object with device specifications.

        Raises:
            RuntimeError: If not connected.
        """
        return self._session.get_device_info()

    async def _ensure_connected(self) -> None:
        """Ensure the client is connected."""
        if not self._connected:
            raise RuntimeError("Client not connected. Call connect() first")

    async def __aenter__(self):
        """Async context manager entry."""
        await self.connect()
        return self

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        """Async context manager exit."""
        await self.disconnect()

__aenter__() async

Async context manager entry.

Source code in src/pypixelcolor/client.py
105
106
107
108
async def __aenter__(self):
    """Async context manager entry."""
    await self.connect()
    return self

__aexit__(exc_type, exc_val, exc_tb) async

Async context manager exit.

Source code in src/pypixelcolor/client.py
110
111
112
async def __aexit__(self, exc_type, exc_val, exc_tb):
    """Async context manager exit."""
    await self.disconnect()

__init__(address)

Initialize the AsyncClient.

Parameters:

Name Type Description Default
address str

Bluetooth device address (e.g., "1D:6B:5E:B5:A5:54")

required
Source code in src/pypixelcolor/client.py
54
55
56
57
58
59
60
61
def __init__(self, address: str):
    """Initialize the AsyncClient.

    Args:
        address: Bluetooth device address (e.g., "1D:6B:5E:B5:A5:54")
    """
    self._session = DeviceSession(address)
    self._connected = False

clear() async

Clears the EEPROM.

Source code in src/pypixelcolor/client.py
36
37
38
    logger.info(f"Command '{command_name}' executed successfully")
else:
    logger.debug(f"Command '{command_name}' executed successfully with data")

connect() async

Connect to the BLE device and retrieve device info.

Source code in src/pypixelcolor/client.py
63
64
65
66
67
68
69
70
async def connect(self) -> None:
    """Connect to the BLE device and retrieve device info."""
    if self._connected:
        logger.warning("Already connected")
        return

    await self._session.connect()
    self._connected = True

delete(n) async

Delete a specific screen by its index.

Source code in src/pypixelcolor/client.py
39
40
# Return the data directly (not the CommandResult wrapper)
# This makes the API cleaner: client.get_device_info() returns DeviceInfo, not CommandResult

disconnect() async

Disconnect from the BLE device.

Source code in src/pypixelcolor/client.py
72
73
74
75
76
77
78
79
async def disconnect(self) -> None:
    """Disconnect from the BLE device."""
    if not self._connected:
        logger.warning("Not connected")
        return

    await self._session.disconnect()
    self._connected = False

get_device_info()

Get cached device information.

Device info is automatically retrieved during connect(). This is a simple getter for the cached data.

Returns:

Type Description
DeviceInfo

DeviceInfo object with device specifications.

Raises:

Type Description
RuntimeError

If not connected.

Source code in src/pypixelcolor/client.py
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def get_device_info(self) -> DeviceInfo:
    """
    Get cached device information.

    Device info is automatically retrieved during connect().
    This is a simple getter for the cached data.

    Returns:
        DeviceInfo object with device specifications.

    Raises:
        RuntimeError: If not connected.
    """
    return self._session.get_device_info()

send_image(path, resize_method=ResizeMethod.CROP, device_info=None, save_slot=0) async

Send an image or animation.

Source code in src/pypixelcolor/client.py
42
43
44
    return result.data

# Preserve the original function's metadata for better introspection

send_image_hex(hex_string, file_extension, resize_method=ResizeMethod.CROP, device_info=None, save_slot=0) async

Send an image or animation from a hexadecimal string.

Source code in src/pypixelcolor/client.py
45
46
method.__name__ = command_name
method.__doc__ = command_func.__doc__

send_text(text, rainbow_mode=0, animation=0, save_slot=0, speed=80, color='ffffff', bg_color=None, font='CUSONG', char_height=None, device_info=None) async

Send a text to the device with configurable parameters.

Source code in src/pypixelcolor/client.py
48
return method

set_brightness(level) async

Set the brightness of the device.

Source code in src/pypixelcolor/client.py
51
52
class AsyncClient:
    """Asynchronous client for controlling the LED matrix via BLE."""

set_clock_mode(style=1, date='', show_date=True, format_24=True) async

Set the clock mode of the device.

Source code in src/pypixelcolor/client.py
54
55
def __init__(self, address: str):
    """Initialize the AsyncClient.

set_fun_mode(enable=False) async

Enable or disable fun mode.

Source code in src/pypixelcolor/client.py
57
58
59
Args:
    address: Bluetooth device address (e.g., "1D:6B:5E:B5:A5:54")
"""

set_orientation(orientation=0) async

Set the orientation of the device.

Source code in src/pypixelcolor/client.py
60
61
self._session = DeviceSession(address)
self._connected = False

set_pixel(x, y, color, device_info=None) async

Defines the color of a specific pixel.

Source code in src/pypixelcolor/client.py
63
64
65
async def connect(self) -> None:
    """Connect to the BLE device and retrieve device info."""
    if self._connected:

set_power(on=True) async

Set the power state of the device.

Source code in src/pypixelcolor/client.py
66
67
logger.warning("Already connected")
return

set_rhythm_mode(style=0, l1=0, l2=0, l3=0, l4=0, l5=0, l6=0, l7=0, l8=0, l9=0, l10=0, l11=0) async

Set the rhythm mode of the device.

Source code in src/pypixelcolor/client.py
69
70
await self._session.connect()
self._connected = True

set_rhythm_mode_2(style=0, t=0) async

Set the rhythm mode of the device (alternative version).

Source code in src/pypixelcolor/client.py
72
73
74
async def disconnect(self) -> None:
    """Disconnect from the BLE device."""
    if not self._connected:

set_time(hour=None, minute=None, second=None) async

Set the device time.

Source code in src/pypixelcolor/client.py
75
76
logger.warning("Not connected")
return

show_slot(number) async

Shows the specified slot on the device.

Source code in src/pypixelcolor/client.py
78
79
await self._session.disconnect()
self._connected = False

version()

Get the client library version.

Source code in src/pypixelcolor/client.py
81
82
83
def version(self) -> str:
    """Get the client library version."""
    return VERSION