pybragerone.models.events¶
Event bus and event classes for pybragerone.
Functions
|
Return the |
Classes
|
Signal that module activity lists should be re-fetched from REST. |
|
Signal that module alarm lists should be re-fetched from REST. |
|
Per-module alarm count changed (REST prime or Socket.IO push). |
|
Typed EventBus channels for additive multi-event fan-out (#408 / #409). |
|
Library ↔ Brager cloud Socket.IO session (client transport health). |
|
One completed connectivity outage episode for diagnostics history (#379). |
|
Multicast bus: |
|
Feature changed event representing a change in device feature state. |
|
Live |
|
Module ↔ Brager cloud connectivity (SPA |
|
Parameter update event carrying value and metadata updates. |
- class pybragerone.models.events.ActivityFeedInvalidate(devid: str, reason: ~typing.Literal['quantity', 'task'], source: ~typing.Literal['ws'] = 'ws', ts: float = <factory>)[source]¶
Bases:
objectSignal that module activity lists should be re-fetched from REST.
Activity rows stay on REST; Socket.IO only indicates that the feed may have changed (quantity badge or task lifecycle events the SPA Activity page watches).
- class pybragerone.models.events.AlarmFeedInvalidate(devid: str, reason: ~typing.Literal['change', 'received'], source: ~typing.Literal['ws'] = 'ws', ts: float = <factory>)[source]¶
Bases:
objectSignal that module alarm lists should be re-fetched from REST.
SPA Alarms UI listens to
app:module:alarms:change/…:receivedand reloads lists — it does not push row payloads on the Socket.IO event.
- class pybragerone.models.events.AlarmQuantityChanged(devid: str, quantity: int | None, source: ~typing.Literal['rest', 'ws'], changed: bool = True, ts: float = <factory>)[source]¶
Bases:
objectPer-module alarm count changed (REST prime or Socket.IO push).
- Parameters:
- class pybragerone.models.events.BusChannel(*values)[source]¶
Bases:
StrEnumTyped EventBus channels for additive multi-event fan-out (#408 / #409).
- ACTIVITY_FEED = 'activity_feed'¶
- ALARM_FEED = 'alarm_feed'¶
- ALARM_QUANTITY = 'alarm_quantity'¶
- CLOUD_SESSION = 'cloud_session'¶
- LIVE_PUSH = 'live_push'¶
- MODULE_CONNECTIVITY = 'module_connectivity'¶
- PARAM = 'param'¶
- class pybragerone.models.events.CloudSessionConnectivity(up: bool, source: ~typing.Literal['connect', 'disconnect', 'stop'], changed: bool = True, ts: float = <factory>, down_since: float | None = None, down_for_s: float | None = None, reason: ~typing.Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None = None, last_down_for_s: float | None = None, last_reason: ~typing.Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None = None)[source]¶
Bases:
objectLibrary ↔ Brager cloud Socket.IO session (client transport health).
Distinct from
ModuleConnectivity(module ↔ cloudconnectedAt). When this session drops the gateway self-heals: Engine.IO reset on connect timeout, supervisor reconnect, resubscribe + REST prime, REST re-prime on the connectivity poll while the socket is still down, and after repeated stale-ParamUpdate cycles a hard WS restart (SPA parity:connect→ModulesService.connect+ REST parameters). Published onBusChannel.CLOUD_SESSIONand viaBragerOneGateway.on_cloud_session(compat); pollBragerOneGateway.ws_session_up()for a snapshot.- Parameters:
up (bool)
source (Literal['connect', 'disconnect', 'stop'])
changed (bool)
ts (float)
down_since (float | None)
down_for_s (float | None)
reason (Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None)
last_down_for_s (float | None)
last_reason (Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None)
- down_for_s: float | None = None¶
Wall-clock
time.time()when the current session-down outage started (Noneif up).
- last_down_for_s: float | None = None¶
Client-side reason for the current down (coarse
disconnect/stopor finer WS tokens such ashandshake_503/eio_close); not plant diagnostics.
- last_reason: Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None = None¶
Duration of the most recently completed session-down outage.
- reason: Literal['disconnect', 'stop', 'handshake_503', 'connect_error', 'empty_queue', 'server_stop', 'eio_close', 'reconnect_error', 'supervisor_stale', 'force_reconnect', 'hard_reset'] | None = None¶
Seconds down so far while
upis false;Nonewhen up.
- class pybragerone.models.events.ConnectivityEpisode(layer: Literal['cloud', 'module', 'live_stale'], started_at: float, ended_at: float, down_for_s: float, reason: str | None = None, devid: str | None = None, episode_id: str | None = None)[source]¶
Bases:
objectOne completed connectivity outage episode for diagnostics history (#379).
- Parameters:
- class pybragerone.models.events.EventBus[source]¶
Bases:
objectMulticast bus:
subscribe()is ParamUpdate-only; channels are additive.subscribe()stays typed toParamUpdateso ParamStore / HA parameter loops stay unbroken. Non-parameter signals are available viasubscribe_channel()(and still via gatewayon_*callbacks for compat). Alarm/activity row lists are never on the bus — REST remains source of truth.- async publish(upd: ParamUpdate)[source]¶
Publish a
ParamUpdatetosubscribe()andPARAMchannel subscribers.- Parameters:
upd (
ParamUpdate) – The parameter update event to publish.- Return type:
- async publish_event(event: ParamUpdate | ModuleConnectivity | CloudSessionConnectivity | LivePushHealth | AlarmQuantityChanged | AlarmFeedInvalidate | ActivityFeedInvalidate)[source]¶
Publish a typed event to the matching channel (and ParamUpdate subscribers).
- Parameters:
event (
ParamUpdate|ModuleConnectivity|CloudSessionConnectivity|LivePushHealth|AlarmQuantityChanged|AlarmFeedInvalidate|ActivityFeedInvalidate) – Gateway event dataclass to fan out.- Return type:
- async subscribe()[source]¶
Subscribe to
ParamUpdateevents only.- Returns:
AsyncGenerator[ParamUpdate] – An async iterator that yields parameter update events.- Return type:
- async subscribe_channel(*channels: BusChannel | str)[source]¶
Subscribe to one or more typed channels.
- Parameters:
*channels (
BusChannel|str) – Channels to receive (BusChannelor matching string values). At least one is required. Duplicates are ignored.- Yields:
Events published on any of the selected channels (FIFO per subscriber).
- Raises:
ValueError – If no channels are provided or a name is not a known channel.
- Return type:
AsyncGenerator[ParamUpdate | ModuleConnectivity | CloudSessionConnectivity | LivePushHealth | AlarmQuantityChanged | AlarmFeedInvalidate | ActivityFeedInvalidate]
- class pybragerone.models.events.FeatureChanged(devid: str, feature: str, value: bool)[source]¶
Bases:
objectFeature changed event representing a change in device feature state.
- class pybragerone.models.events.LivePushHealth(healthy: bool | None, live_stale_for_s: float | None = None, last_resumed_after_s: float | None = None, changed: bool = True, ts: float = <factory>)[source]¶
Bases:
objectLive
ParamUpdatepush health while the Socket.IO session is up.Distinct from
CloudSessionConnectivity(transport up/down) andModuleConnectivity(moduleconnectedAt). A zombie session isup=Truewithhealthy=False/live_stale_for_sset.- Parameters:
- last_resumed_after_s: float | None = None¶
Seconds since the last live
ParamUpdatewhile push is unhealthy.
- class pybragerone.models.events.ModuleConnectivity(devid: str, online: bool, source: ~typing.Literal['rest', 'ws', 'derived'], connected_at: int | None = None, gateway: dict[str, ~typing.Any] | None = None, online_changed: bool = True, metadata_changed: bool = False, ts: float = <factory>, down_since: float | None = None, down_for_s: float | None = None, reason: ~typing.Literal['rest', 'ws', 'derived'] | None = None, last_down_for_s: float | None = None, last_reason: ~typing.Literal['rest', 'ws', 'derived'] | None = None)[source]¶
Bases:
objectModule ↔ Brager cloud connectivity (SPA
connectedAt).Published on
EventBuschannelBusChannel.MODULE_CONNECTIVITYand viaBragerOneGateway.on_module_connectivity(compat). PollBragerOneGateway.module_online()when a snapshot is enough.Mirrors the SPA module card / connection modal: online iff
connectedAtis truthy (upstream uses0as offline). Live updates arrive on Socket.IOapp:module:connection:status:changedwith{devid: {connectedAt, gateway}}.When the module is offline there is nothing the client can repair — observe and wait. The library’s own Socket.IO session is a separate layer (
CloudSessionConnectivity) and must never be folded intoonline.- Parameters:
devid (str)
online (bool)
source (Literal['rest', 'ws', 'derived'])
connected_at (int | None)
online_changed (bool)
metadata_changed (bool)
ts (float)
down_since (float | None)
down_for_s (float | None)
reason (Literal['rest', 'ws', 'derived'] | None)
last_down_for_s (float | None)
last_reason (Literal['rest', 'ws', 'derived'] | None)
- connected_at: int | None = None¶
Where the observation came from (REST poll, WS push, or derived absence).
- down_for_s: float | None = None¶
Wall-clock
time.time()when the current offline outage started (Noneif online).
- gateway: dict[str, Any] | None = None¶
Raw
connectedAtepoch seconds when known (0means offline upstream).
- last_down_for_s: float | None = None¶
Client-side observation source for the current outage (
rest/ws/derived).
- last_reason: Literal['rest', 'ws', 'derived'] | None = None¶
Duration of the most recently completed offline outage.
- class pybragerone.models.events.ParamUpdate(devid: str, pool: str, chan: str, idx: int, value: Any | None, meta: dict[str, ~typing.Any]=<factory>, ts: float = <factory>, seq: int = 0)[source]¶
Bases:
objectParameter update event carrying value and metadata updates.
- Parameters:
- pybragerone.models.events.channel_for_event(event: ParamUpdate | ModuleConnectivity | CloudSessionConnectivity | LivePushHealth | AlarmQuantityChanged | AlarmFeedInvalidate | ActivityFeedInvalidate)[source]¶
Return the
BusChannelfor a typed gateway event.Exact type matches first; otherwise the nearest registered base class via
isinstance(soParamUpdatesubclasses keep working).- Parameters:
event (
ParamUpdate|ModuleConnectivity|CloudSessionConnectivity|LivePushHealth|AlarmQuantityChanged|AlarmFeedInvalidate|ActivityFeedInvalidate) – Event instance to route.- Returns:
BusChannel– Matching bus channel.- Raises:
TypeError – If event is not a known
GatewayEventtype.- Return type: