pybragerone.api.ws

WebSocket (Socket.IO) client for BragerOne realtime events.

Classes

EventDispatcher(*args, **kwargs)

Protocol for an event dispatcher used by the realtime manager.

RealtimeManager(token, *[, origin, referer, ...])

Thin Socket.IO wrapper for BragerOne realtime channel.

class pybragerone.api.ws.EventDispatcher(*args, **kwargs)[source]

Bases: Protocol

Protocol for an event dispatcher used by the realtime manager.

class pybragerone.api.ws.RealtimeManager(token: str, *, origin: str = 'https://one.brager.pl', referer: str = 'https://one.brager.pl/', io_base: str = 'https://io.brager.pl', socket_path: str = '/socket.io', namespace: str = '/ws')[source]

Bases: object

Thin Socket.IO wrapper for BragerOne realtime channel.

The manager keeps a single AsyncClient connection, exposes the Engine.IO SID and the namespace SID, and forwards selected events to a user-provided callback (EventHandler). It does not interpret payloads; that is the gateway’s responsibility.

Notes

  • Authentication is provided only via HTTP headers (Bearer token).

  • We always connect to the :data:`~.constants.WS_NAMESPACE` namespace.

  • We listen to: snapshot and the various *:parameters:change events.

  • Subscriptions are emitted in a few payload variants (modules / devids) and optionally include group_id.

Parameters:
add_on_connected(cb: Callable[[], None | Awaitable[None]])[source]

Register a callback to be called when the connection is established.

Return type:

None

Parameters:

cb (Callable[[], None | Awaitable[None]])

async connect()[source]

Open a Socket.IO connection with appropriate headers and wait for join.

Return type:

None

async disconnect()[source]

Close the Socket.IO connection if open.

Return type:

None

engine_sid()[source]

Return the underlying Engine.IO SID (transport-level).

Return type:

str | None

property group_id: int | None

Return the optional group_id included in subscription payloads.

on_event(handler: EventDispatcher)[source]

Register a single event dispatcher (gateway attaches here).

Return type:

None

Parameters:

handler (EventDispatcher)

async resubscribe()[source]

Re-emit subscription events after a reconnect.

Return type:

None

sid()[source]

Return the namespace SID (/ws), if available.

Return type:

str | None

async subscribe(modules: list[str])[source]

Emit listen events for the provided devices (devids/modules).

Return type:

None

Parameters:

modules (list[str])