pybragerone.gateway¶
Gateway: WS connect → modules.connect → listen → prime.
Maintains the WS connection and emits ParamUpdate events on the EventBus. Does not contain heavy logic (such as mapping) internally — this is the role of ParamStore/HA.
Classes
|
Protocol for the HTTP client used by the gateway. |
|
High-level orchestrator for BragerOne realtime data. |
|
Protocol for the WS client used by the gateway. |
- class pybragerone.gateway.ApiClient(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for the HTTP client used by the gateway.
This makes the gateway easy to test by allowing a lightweight fake.
- class pybragerone.gateway.BragerOneGateway(*, api: ApiClient, object_id: int, modules: Iterable[str], ws: RealtimeManagerClient | None = None, owns_api: bool = False)[source]¶
Bases:
objectHigh-level orchestrator for BragerOne realtime data.
- Flow:
ensure_auth (proactive/reactive refresh in HTTP client)
Socket.IO connect → modules.connect (binding WS with DEV)
subscribe to streams (parameters, activity)
“prime” (REST snapshot of parameters + activity quantities)
EventBus emits ParamUpdate for consumers (ParamStore/HA/CLI)
- Parameters:
api (ApiClient)
object_id (int)
modules (Iterable[str])
ws (RealtimeManagerClient | None)
owns_api (bool)
- flatten_parameters(payload: dict[str, Any], *, source: str = 'unknown')[source]¶
Convert WS/REST parameter payload into ParamUpdate events.
- async classmethod from_credentials(*, email: str, password: str, object_id: int, modules: Iterable[str], server: ServerConfig | None = None, ws: RealtimeManagerClient | None = None, api: TypeAliasForwardRef('pybragerone.api.BragerOneApiClient') | None = None)[source]¶
Create a gateway from credentials.
This is a convenience helper for CLI/examples.
- Parameters:
email (
str) – BragerOne account email.password (
str) – BragerOne account password.object_id (
int) – BragerOne object/group ID.server (
ServerConfig|None) – Optional server/platform configuration (e.g. TiSConnect).ws (
RealtimeManagerClient|None) – Optional WS client instance (testing).api (
Optional[pybragerone.api.BragerOneApiClient]) – Optional API client instance (testing/customization).
- Returns:
BragerOneGateway– An initialized gateway (not started).- Return type:
- async ingest_activity_quantity(data: dict[str, Any] | None)[source]¶
Ingest /modules/activity/quantity prime (optional).
- async ingest_prime_parameters(data: dict[str, Any])[source]¶
Treat /modules/parameters prime as “cold snapshot” and publish all pairs.
- on_any(cb: Callable[[str, Any], Awaitable[None] | None])[source]¶
Register callback for any WS event for diagnostics.
- on_parameters_change(cb: Callable[[str, dict[str, Any]], Awaitable[None] | None])[source]¶
Register callback for app:modules:parameters:change.
- on_snapshot(cb: Callable[[dict[str, Any]], Awaitable[None] | None])[source]¶
Register callback for snapshot event (full state-like payload).