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.
Connectivity is two layers, both off the ParamUpdate EventBus:
Module ↔ cloud — SPA
connectedAtviaon_module_connectivity(observe/wait).Library ↔ cloud — Socket.IO session via
on_cloud_session(detect + self-heal).
Functions
|
Return whether a |
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, connectivity_poll_interval: float = 60.0, stale_prime_after_s: float = 180.0, zombie_hard_restart_after: int = 2, zombie_full_recycle_after: int = 3, zombie_rebuild_after: int = 2, zombie_recovery_cooldown_s: float = 300.0)[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)
Background REST poll of
get_modulesdiffsconnectedAtand notifieson_module_connectivity(module↔cloud; separate from EventBus)Socket.IO up/down notifies
on_cloud_session(library↔cloud; self-healing)
- Parameters:
- 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, connectivity_poll_interval: float = 60.0)[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).connectivity_poll_interval (
float) – See__init__().
- 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_alarm_quantity(data: dict[str, Any] | None, *, source: Literal['rest', 'ws'] = 'rest', ws_floor: dict[str, int] | None = None, rest_seq: int | None = None)[source]¶
Ingest alarm quantity payload and notify
on_alarm_quantitylisteners.
- async ingest_prime_parameters(data: dict[str, Any])[source]¶
Treat /modules/parameters prime as “cold snapshot” and publish all pairs.
- last_live_param_update_age_s()[source]¶
Return seconds since the last live (WS)
ParamUpdate, orNoneif never.
- last_param_update_age_s()[source]¶
Return seconds since the last published
ParamUpdate, orNoneif never.
- module_gateway(devid: str)[source]¶
Return the last gateway blob for devid (address/interface/version).
- on_alarm_quantity(cb: Callable[[AlarmQuantityChanged], Awaitable[None] | None])[source]¶
Register callback for per-module alarm count changes.
Callbacks receive
AlarmQuantityChangedwhen REST prime or Socket.IOapp:modules:alarms:quantity:changereports a new count for a subscribed module.- Return type:
- Parameters:
cb (Callable[[AlarmQuantityChanged], Awaitable[None] | None])
- on_any(cb: Callable[[str, Any], Awaitable[None] | None])[source]¶
Register callback for any WS event for diagnostics.
- on_cloud_session(cb: Callable[[CloudSessionConnectivity], Awaitable[None] | None])[source]¶
Register callback for library↔cloud Socket.IO session up/down.
Callbacks receive
CloudSessionConnectivity. Distinct fromon_module_connectivity(): a dropped client session must self-heal and stay detectable without looking like a module went offline.- Return type:
- Parameters:
cb (Callable[[CloudSessionConnectivity], Awaitable[None] | None])
- on_module_connectivity(cb: Callable[[ModuleConnectivity], Awaitable[None] | None])[source]¶
Register callback for module↔cloud online/offline (SPA
connectedAt).Callbacks receive
ModuleConnectivity. This path is intentionally separate frombussoParamUpdatesubscribers stay unchanged. Offline modules are observed only — the client cannot repair plant↔cloud links.- Return type:
- Parameters:
cb (Callable[[ModuleConnectivity], Awaitable[None] | None])
- 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).
- async refresh_module_connectivity()[source]¶
Refresh module↔cloud connectivity from REST
get_modules.- Return type:
- class pybragerone.gateway.RealtimeManagerClient(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for the WS client used by the gateway.