Протокол 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='', ha_serial_prefix=None)
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. |
''
|
ha_serial_prefix
|
str | None
|
When set, the hub device gets a
|
None
|
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
resolve_ha_serial_number
¶
Resolve the ha_serial_number marker for one entity.
Priority
- Real
DeviceEntry.serial_numberif linked to a device. - Normalised MAC from
DeviceEntry.connections. - Fallback
f"ha-{ha_serial_prefix}"(per-HA-instance marker).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
BaseEntity
|
Entity whose |
required |
ha_serial_prefix
|
str
|
First N chars of the HA instance UUID (used as fallback when the device has no real serial / MAC). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Non-empty string suitable for |
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, ha_serial_prefix=None)
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
|
ha_serial_prefix
|
str | None
|
Per-HA-instance serial prefix. When provided,
every device (including the hub) receives a
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
Tuple |
bool
|
|
list[str]
|
validation and were excluded from the payload. |
Source code in custom_components/sber_mqtt_bridge/sber_protocol.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 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 | |
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).