Модели протокола¶
Pydantic-модели для валидации и конструирования JSON-структур протокола Sber Smart Home.
Pydantic models for Sber Smart Home MQTT protocol.
Provides typed schemas for Sber protocol payloads (device config, states, commands) and helper functions for constructing protocol values.
These models serve as: - Reference documentation for the Sber JSON protocol - Optional validation layer for outgoing MQTT payloads - Type-safe constructors for Sber state values
SberValue
¶
Bases: BaseModel
A typed value in Sber state or command payload.
Sber protocol uses tagged unions: the type field selects which
*_value field carries the actual data.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal['BOOL', 'INTEGER', 'FLOAT', 'STRING', 'ENUM', 'COLOUR']
|
Value type discriminator. |
bool_value |
bool | None
|
Boolean payload (for |
integer_value |
str | None
|
Integer payload as string (for |
float_value |
float | None
|
Float payload (for |
string_value |
str | None
|
String payload (for |
enum_value |
str | None
|
Enum string payload (for |
colour_value |
dict[str, int] | None
|
HSV colour dict (for |
SberState
¶
Bases: BaseModel
Single state key-value pair in the Sber protocol.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
str
|
State key name (e.g. |
value |
SberValue
|
Typed value for the key. |
SberDeviceModel
¶
Bases: BaseModel
Device model descriptor within a Sber device config.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Model identifier string. |
manufacturer |
str
|
Device manufacturer name. |
model |
str
|
Device model name. |
description |
str
|
Human-readable description. |
category |
str
|
Sber device category (e.g. |
features |
list[str]
|
List of supported feature keys. |
allowed_values |
dict[str, Any]
|
Optional dict of feature constraints. |
SberDevice
¶
Bases: BaseModel
Full device descriptor for Sber config publish.
Per Sber spec (VR-001), model_id and model are mutually exclusive.
This integration always uses inline model; model_id is not emitted.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Device / entity identifier. |
name |
str
|
Display name. |
default_name |
str | None
|
Fallback name (usually entity_id). |
room |
str
|
Room / area identifier. |
home |
str | None
|
Home / location name (e.g. "Мой дом"). |
model |
SberDeviceModel
|
Nested device model descriptor (mutually exclusive with model_id). |
hw_version |
str
|
Hardware version string. |
sw_version |
str
|
Software version string. |
nicknames |
list[str] | None
|
Alternative voice names. |
groups |
list[str] | None
|
Device groups. |
parent_id |
str | None
|
Parent device entity_id for hub hierarchy. |
partner_meta |
dict[str, str] | None
|
Arbitrary key-value metadata for partner integrations. |
SberDeviceState
¶
Bases: BaseModel
Current state of a single device.
Attributes:
| Name | Type | Description |
|---|---|---|
states |
list[SberState]
|
List of state key-value pairs. |
SberConfigPayload
¶
Bases: BaseModel
Config publish payload (device list).
Attributes:
| Name | Type | Description |
|---|---|---|
devices |
list[SberDevice | dict[str, Any]]
|
List of device descriptors (SberDevice or raw dict). |
SberStatusPayload
¶
Bases: BaseModel
Status publish payload (device states).
Attributes:
| Name | Type | Description |
|---|---|---|
devices |
dict[str, SberDeviceState]
|
Mapping of device_id to its current state. |
SberCommandPayload
¶
Bases: BaseModel
Incoming command payload from Sber cloud.
Attributes:
| Name | Type | Description |
|---|---|---|
devices |
dict[str, SberDeviceState]
|
Mapping of device_id to command states. |
make_bool_value
¶
Create a Sber BOOL value dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
Boolean value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict ready for inclusion in a Sber state payload. |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
make_integer_value
¶
Create a Sber INTEGER value dict.
Per Sber C2C specification, integer_value is serialized as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
int
|
Integer value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict ready for inclusion in a Sber state payload. |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
make_enum_value
¶
Create a Sber ENUM value dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Enum string value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict ready for inclusion in a Sber state payload. |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
make_colour_value
¶
Create a Sber COLOUR value dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
int
|
Hue component (0-360). |
required |
s
|
int
|
Saturation component (0-100). |
required |
v
|
int
|
Value/brightness component (0-100). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict ready for inclusion in a Sber state payload. |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
make_state
¶
Create a Sber state entry dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
State key name. |
required |
value
|
dict[str, Any]
|
Typed value dict (from |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
validate_config_payload
¶
Validate a config payload dict against the SberConfigPayload schema.
This is an optional validation step — failures are logged as warnings but do not prevent publishing (the raw dict is still valid JSON).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Raw dict to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if validation passed, False otherwise. |
Source code in custom_components/sber_mqtt_bridge/sber_models.py
validate_status_payload
¶
Validate a status payload dict against the SberStatusPayload schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Raw dict to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if validation passed, False otherwise. |