Skip to content

Async Client

AsyncSignalRGBClient is the native httpx async client — the primary implementation that the sync client wraps. Use it for asyncio applications and Home Assistant integrations.

Constructor

python
from signalrgb import AsyncSignalRGBClient

client = AsyncSignalRGBClient(
    host="localhost",
    port=16038,
    timeout=10.0,
)

Context manager

python
async with AsyncSignalRGBClient() as client:
    effect = await client.get_current_effect()
    print(effect.attributes.name)
# aclose() called automatically

Or manual cleanup:

python
client = AsyncSignalRGBClient()
try:
    await client.get_effects()
finally:
    await client.aclose()

Sync vs async API

The async client uses explicit methods instead of properties (properties can't be async):

Sync propertyAsync method
client.brightnessawait client.get_brightness()
client.brightness = 50await client.set_brightness(50)
client.enabledawait client.get_enabled()
client.enabled = Trueawait client.set_enabled(True)
client.current_layoutawait client.get_current_layout()
client.current_layout = "x"await client.set_current_layout("x")

Effects

MethodReturns
await get_effects()list[Effect]
await get_effect(id)Effect
await get_effect_by_name(name)Effect
await get_current_effect()Effect
await apply_effect(id)None
await apply_effect_by_name(name)None
await apply_next_effect()Effect
await apply_previous_effect()Effect
await apply_random_effect()Effect
await refresh_effects()None

Presets

MethodReturns
await get_effect_presets(effect_id)list[EffectPreset]
await apply_effect_preset(effect_id, preset_id)None

Layouts

MethodReturns
await get_layouts()list[Layout]
await get_current_layout()Layout
await set_current_layout(id)None

Home Assistant example

python
from homeassistant.components.light import LightEntity
from signalrgb import AsyncSignalRGBClient


class SignalRGBLight(LightEntity):
    def __init__(self, client: AsyncSignalRGBClient) -> None:
        self._client = client
        self._state = False
        self._brightness = 0

    async def async_turn_on(self, **kwargs) -> None:
        await self._client.set_enabled(True)
        if "brightness" in kwargs:
            # HA brightness is 0–255, SignalRGB is 0–100
            await self._client.set_brightness(
                round(kwargs["brightness"] / 255 * 100)
            )
        self._state = True

    async def async_turn_off(self, **kwargs) -> None:
        await self._client.set_enabled(False)
        self._state = False

    async def async_update(self) -> None:
        self._state = await self._client.get_enabled()
        self._brightness = await self._client.get_brightness()

See signalrgb-homeassistant for the full integration.

Released under the Apache 2.0 License.