Протокол Sber Smart Home¶
JSON-сериализация для обмена данными с облаком Sber Smart Home.
Sber Smart Home MQTT protocol serialization.
Handles conversion of internal device entities to Sber JSON formats for MQTT communication (device config, state lists, command parsing).
VERSION
module-attribute
¶
Protocol version string included in the hub device descriptor.
build_hub_device
¶
build_hub_device(version=VERSION, home='', room='')
Build the root hub device descriptor for Sber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Protocol version string. |
VERSION
|
home
|
str
|
Home name for the hub device. |
''
|
room
|
str
|
Room name for the hub device. |
''
|
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
build_devices_list_json
¶
build_devices_list_json(entities, enabled_entity_ids, redefinitions=None, default_home='', default_room='', auto_parent_id=True)
Build Sber device config JSON for MQTT publish.
The resulting payload is validated against :class:SberConfigPayload
(pydantic) before serialisation. Validation failures are logged as
warnings but do not prevent publishing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
dict[str, BaseEntity]
|
Dict of entity_id -> BaseEntity instances. |
required |
enabled_entity_ids
|
list[str]
|
List of entity_ids to include. |
required |
redefinitions
|
dict[str, dict] | None
|
Optional dict of entity_id -> {home, room, name} overrides. |
None
|
default_home
|
str
|
Fallback home name (from HA location_name) when not set via redefinitions. Sber cloud may reject devices without it. |
''
|
default_room
|
str
|
Fallback room name when device has no area assigned. Sber cloud may reject devices without a room. |
''
|
auto_parent_id
|
bool
|
When True, automatically set |
True
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string with the Sber device list payload. |
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
build_states_list_json
¶
Build Sber state list JSON for MQTT publish.
The resulting payload is validated against :class:SberStatusPayload
(pydantic) before serialisation. Validation failures are logged as
warnings but do not prevent publishing — Sber may still accept
a partially valid payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
dict[str, BaseEntity]
|
Dict of entity_id -> BaseEntity instances. |
required |
entity_ids
|
list[str] | None
|
Specific entity_ids to include (None = all enabled). |
None
|
enabled_entity_ids
|
list[str] | None
|
List of enabled entity_ids (used when entity_ids is None). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, bool]
|
Tuple of (JSON string, validation_passed bool). |
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
parse_sber_command
¶
Parse Sber MQTT command payload.
Per spec (VR-032), devices must be a dict keyed by device_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
bytes | str
|
Raw MQTT payload (bytes or str). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed dict with 'devices' key, or empty dict on parse error. |
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
parse_sber_status_request
¶
Parse Sber status request payload.
Returns list of requested entity_ids (empty = all).