Перейти к содержанию

Реле и розетки

RelayEntity

Реле: switch, script, button (on/off управление).

Sber Relay entity -- maps HA switch/script/button to Sber relay category.

RELAY_CATEGORY module-attribute

RELAY_CATEGORY = 'relay'

Sber device category for relay/switch entities.

RelayEntity

RelayEntity(entity_data, category=RELAY_CATEGORY)

Bases: OnOffEntity

Sber relay entity for on/off control devices.

Maps HA switch, script, and button entities to the Sber 'relay' category. Supports basic on/off toggling via the on_off Sber feature.

Initialize relay entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
category str

Sber device category (override in subclasses).

RELAY_CATEGORY
Source code in custom_components/sber_mqtt_bridge/devices/relay.py
def __init__(self, entity_data: dict, category: str = RELAY_CATEGORY) -> None:
    """Initialize relay entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
        category: Sber device category (override in subclasses).
    """
    super().__init__(category, entity_data)

SocketEntity

Умная розетка.

Sber Socket entity -- maps HA outlet switches to Sber socket category.

SOCKET_CATEGORY module-attribute

SOCKET_CATEGORY = 'socket'

Sber device category for smart socket/outlet entities.

SocketEntity

SocketEntity(entity_data)

Bases: RelayEntity

Sber socket entity for smart outlet/plug devices.

Inherits all relay behavior (on/off control) but registers under the Sber 'socket' category instead of 'relay'.

Initialize socket entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/socket_entity.py
def __init__(self, entity_data: dict) -> None:
    """Initialize socket entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(entity_data, category=SOCKET_CATEGORY)

ValveEntity

Клапан (водоснабжение, газ).

Sber Valve entity -- maps HA valve entities to Sber valve category.

Uses open_set/open_state features (NOT on_off). Per Sber specification, valve is controlled via ENUM open/close/stop commands. Supports optional battery and signal strength reporting.

VALVE_CATEGORY module-attribute

VALVE_CATEGORY = 'valve'

Sber device category for valve entities.

ValveEntity

ValveEntity(entity_data)

Bases: BatteryAndSignalLinkMixin, BaseEntity

Sber valve entity for open/close valve control.

Maps HA valve entities to the Sber 'valve' category. Uses open_set (command) and open_state (state) features per Sber specification. Does NOT use on_off.

Optionally reports battery_percentage, battery_low_power, and signal_strength when the HA entity provides these attributes.

Initialize valve entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/valve.py
def __init__(self, entity_data: dict) -> None:
    """Initialize valve entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(VALVE_CATEGORY, entity_data)
    self.is_open: bool = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update open/close status, battery, and signal.

Parameters:

Name Type Description Default
ha_state dict

HA state dict with 'state' and 'attributes' keys.

required
Source code in custom_components/sber_mqtt_bridge/devices/valve.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update open/close status, battery, and signal.

    Args:
        ha_state: HA state dict with 'state' and 'attributes' keys.
    """
    super().fill_by_ha_state(ha_state)
    self.is_open = ha_state.get("state") == "open"
    self._apply_attr_specs(ha_state.get("attributes", {}))

create_allowed_values_list

create_allowed_values_list()

Return allowed values for the open_set feature.

Source code in custom_components/sber_mqtt_bridge/devices/valve.py
def create_allowed_values_list(self) -> dict[str, dict]:
    """Return allowed values for the open_set feature."""
    return {
        "open_set": {
            "type": "ENUM",
            "enum_values": {"values": ["open", "close", "stop"]},
        },
    }

to_sber_current_state

to_sber_current_state()

Build Sber current state payload with online, open_state, battery, and signal.

Returns:

Type Description
dict[str, dict]

Dict mapping entity_id to its Sber state representation.

Source code in custom_components/sber_mqtt_bridge/devices/valve.py
def to_sber_current_state(self) -> dict[str, dict]:
    """Build Sber current state payload with online, open_state, battery, and signal.

    Returns:
        Dict mapping entity_id to its Sber state representation.
    """
    states = [
        make_state(SberFeature.ONLINE, make_bool_value(self._is_online)),
        make_state(SberFeature.OPEN_STATE, make_enum_value("open" if self.is_open else "close")),
        make_state(SberFeature.OPEN_PERCENTAGE, make_integer_value(100 if self.is_open else 0)),
    ]
    self._append_battery_signal_states(states)
    return {self.entity_id: {"states": states}}

ScenarioButtonEntity

Кнопка сценария (input_boolean).

Sber Scenario Button entity -- maps HA input_boolean to Sber scenario_button.

SCENARIO_BUTTON_CATEGORY module-attribute

SCENARIO_BUTTON_CATEGORY = 'scenario_button'

Sber device category for scenario button entities.

ScenarioButtonEntity

ScenarioButtonEntity(entity_data)

Bases: BaseEntity

Sber scenario button entity.

Maps HA input_boolean entities to the Sber 'scenario_button' category. Reports button events (click / double_click) based on the boolean state.

Initialize scenario button entity.

Parameters:

Name Type Description Default
entity_data dict

HA entity registry dict containing entity metadata.

required
Source code in custom_components/sber_mqtt_bridge/devices/scenario_button.py
def __init__(self, entity_data: dict) -> None:
    """Initialize scenario button entity.

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(SCENARIO_BUTTON_CATEGORY, entity_data)
    self.button_event = "click"

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update button event type.

Maps 'on' to 'click' and anything else to 'double_click'.

Parameters:

Name Type Description Default
ha_state dict

HA state dict with 'state' key.

required
Source code in custom_components/sber_mqtt_bridge/devices/scenario_button.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update button event type.

    Maps 'on' to 'click' and anything else to 'double_click'.

    Args:
        ha_state: HA state dict with 'state' key.
    """
    super().fill_by_ha_state(ha_state)
    state = ha_state.get("state")
    if state in ("unavailable", "unknown"):
        return
    if state == "on":
        self.button_event = "click"
    else:
        self.button_event = "double_click"

create_allowed_values_list

create_allowed_values_list()

Return allowed values for button_event feature.

Source code in custom_components/sber_mqtt_bridge/devices/scenario_button.py
def create_allowed_values_list(self) -> dict[str, dict]:
    """Return allowed values for button_event feature."""
    return {
        "button_event": {
            "type": "ENUM",
            "enum_values": {"values": ["click", "double_click", "long_press"]},
        },
    }

to_sber_current_state

to_sber_current_state()

Build Sber current state payload with online and button_event keys.

Returns:

Type Description
dict[str, dict]

Dict mapping entity_id to its Sber state representation.

Source code in custom_components/sber_mqtt_bridge/devices/scenario_button.py
def to_sber_current_state(self) -> dict[str, dict]:
    """Build Sber current state payload with online and button_event keys.

    Returns:
        Dict mapping entity_id to its Sber state representation.
    """
    states = [
        make_state(SberFeature.ONLINE, make_bool_value(self._is_online)),
        make_state(SberFeature.BUTTON_EVENT, make_enum_value(self.button_event)),
    ]
    return {self.entity_id: {"states": states}}