SberBridge¶
Ядро интеграции: управление MQTT-соединением к Sber Cloud, диспетчеризация команд, отслеживание состояний HA-устройств.
Sber Smart Home MQTT Bridge - core bridge logic.
Manages: - Async MQTT connection to Sber cloud broker (aiomqtt) - HA state change listening and publishing to Sber - Sber command reception and forwarding to HA services - Connection health monitoring and device acknowledgment tracking
RECONNECT_INTERVAL_MIN
module-attribute
¶
Default minimum seconds to wait before reconnecting after an MQTT connection loss.
RECONNECT_INTERVAL_MAX
module-attribute
¶
Default maximum seconds to wait (5 minutes) with exponential backoff.
MAX_MQTT_PAYLOAD_SIZE
module-attribute
¶
Default maximum MQTT payload size in bytes (1 MB) to prevent DoS from oversized messages.
RECONNECT_GRACE_TIMEOUT
module-attribute
¶
Maximum seconds to wait for Sber acknowledgment after (re)connect.
After a reconnect, the bridge publishes HA states and waits for Sber to acknowledge them (via status_request or config_request) before accepting commands. This timeout is a fallback in case Sber never sends a request.
BridgeStats
dataclass
¶
BridgeStats(connected_since=None, messages_received=0, messages_sent=0, commands_received=0, config_requests=0, status_requests=0, errors_from_sber=0, publish_errors=0, last_message_time=None, reconnect_count=0, acknowledged_entities=set(), last_error_detail='', last_ack_time=None, validation_failures=list())
Connection statistics and health metrics for the Sber MQTT bridge.
connected_since
class-attribute
instance-attribute
¶
Timestamp when the current connection was established.
messages_received
class-attribute
instance-attribute
¶
Total MQTT messages received from Sber.
messages_sent
class-attribute
instance-attribute
¶
Total MQTT messages published to Sber.
commands_received
class-attribute
instance-attribute
¶
Total Sber commands processed.
config_requests
class-attribute
instance-attribute
¶
Total config requests received from Sber.
status_requests
class-attribute
instance-attribute
¶
Total status requests received from Sber.
errors_from_sber
class-attribute
instance-attribute
¶
Total error messages received from Sber.
publish_errors
class-attribute
instance-attribute
¶
Total failed publish attempts.
last_message_time
class-attribute
instance-attribute
¶
Timestamp of the last message received.
reconnect_count
class-attribute
instance-attribute
¶
Total number of reconnections since startup.
acknowledged_entities
class-attribute
instance-attribute
¶
Entity IDs that Sber has acknowledged (via status_request or command).
last_error_detail
class-attribute
instance-attribute
¶
Human-readable detail of the last error message from Sber cloud.
last_ack_time
class-attribute
instance-attribute
¶
Timestamp (monotonic) of the last Sber acknowledgment received.
validation_failures
class-attribute
instance-attribute
¶
Entity IDs that failed pydantic validation and were excluded from last config.
as_dict
¶
Return stats as a serializable dict.
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
SberBridge
¶
Bridge between Home Assistant and Sber Smart Home MQTT cloud.
Initialize the bridge.
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
connection_phase
property
¶
Return the current connection lifecycle phase.
Phases
starting — HA not fully loaded, waiting for integrations.
connecting — MQTT connection in progress.
awaiting_ack — connected, published config, waiting for Sber to acknowledge.
ready — fully operational, accepting commands.
disconnected — not connected to MQTT broker.
ha_serial_prefix
property
¶
Return active per-HA serial prefix, or None when feature is off.
unacknowledged_entities
property
¶
Return entity IDs that were published but not yet acknowledged by Sber.
message_log
property
¶
Return the DevTools outbound-message ring buffer (delegates to hub).
trace_collector
property
¶
Return the correlation-trace collector (delegates to hub).
validation_collector
property
¶
Return the schema-validation collector (delegates to hub).
async_update_redefinition
async
¶
Merge redefinition fields for an entity and trigger config republish.
Public API for frontend / WebSocket handlers to update a device's
Sber-side name / room / home without reaching into private state.
Delegates data mutation and debounced persistence to
:meth:RedefinitionsStore.async_update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
Target Sber entity identifier (must exist in the bridge). |
required |
fields
|
dict[str, str | None]
|
Partial mapping with any of |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Resulting redefinitions dict for the entity after merge. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
HomeAssistantError
|
If the follow-up config publish fails. |
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_republish_config
async
¶
clear_message_log
¶
apply_settings
¶
Apply changed operational settings without full bridge restart.
Settings that take effect immediately: debounce_delay, max_mqtt_payload_size, message_log_size. Settings that take effect on next reconnect: reconnect_min, reconnect_max, verify_ssl.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options
|
dict
|
Config entry options dict. |
required |
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_publish_raw
async
¶
Publish arbitrary JSON payload to Sber MQTT for debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
str
|
Raw JSON string to publish. |
required |
target
|
str
|
Topic suffix — either "config" or "status". |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If not connected to MQTT broker. |
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_inject_sber_message
async
¶
Feed a synthetic message into the dispatcher as if Sber sent it.
Used by DevTools Replay / Inject: takes a topic (full
sbdev/.../down/commands or a bare suffix like commands)
and runs it through the normal inbound pipeline —
:class:SberCommandDispatcher, correlation trace, state diff,
ack audit — without going through the MQTT broker. No network
round-trip means an injected command flows even when the bridge
is offline, which is exactly what users want when debugging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic
|
str
|
Either the full MQTT topic as it would arrive from
Sber cloud, or just the last segment (suffix) which is
automatically expanded to |
required |
payload
|
str | bytes
|
Raw JSON body. Bytes pass through as-is; strings are UTF-8 encoded to match the real on-wire shape. |
required |
mark_replay
|
bool
|
When True (default), the DevTools message log
records the direction as |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with |
dict[str, Any]
|
|
dict[str, Any]
|
for the given suffix (unknown topic). |
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
subscribe_messages
¶
Subscribe to new MQTT messages in real time (delegates to hub).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback_fn
|
Callable[[dict], None]
|
Called with each new message dict. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[], None]
|
Unsubscribe callable. |
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_start
async
¶
Start the bridge: load entities, subscribe to HA events, connect MQTT.
HA state events are subscribed immediately (independent of MQTT connectivity) so that no state changes are lost while waiting for the first connection. MQTT connection is established in a background task with exponential backoff.
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_stop
async
¶
Stop the bridge: disconnect MQTT, unsubscribe from HA events.
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
refresh_repair_issues
¶
Recompute HA repair issues without awaiting.
Wraps :func:check_and_create_issues in a safe background task so
callers (notably the command dispatcher) can fire-and-forget after
an ack arrives. No-op when HA is not yet running so we don't fight
the early-startup grace window in :meth:_load_exposed_entities.
Source code in custom_components/sber_mqtt_bridge/sber_bridge.py
async_publish_entity_status
async
¶
Publish the current state of a single entity to Sber cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
str
|
HA entity identifier. |
required |