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())
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).
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
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.
unacknowledged_entities
property
¶
Return entity IDs that were published but not yet acknowledged by Sber.
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
subscribe_messages
¶
Subscribe to new MQTT messages in real time.
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
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 |