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

Шторы и ворота

CurtainEntity

Шторы/жалюзи с управлением позицией.

Sber Curtain entity -- maps HA cover entities to Sber curtain category.

CURTAIN_ENTITY_CATEGORY module-attribute

CURTAIN_ENTITY_CATEGORY = 'curtain'

Sber device category for curtain/cover entities.

CurtainEntity

CurtainEntity(entity_data, category=CURTAIN_ENTITY_CATEGORY)

Bases: BatteryAndSignalLinkMixin, BaseEntity

Sber curtain entity for cover control with position support.

Maps HA cover entities to the Sber 'curtain' category with support for: - Position control (0-100%) - Open/close/stop commands - Open state reporting

Initialize curtain 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).

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

    Args:
        entity_data: HA entity registry dict containing entity metadata.
        category: Sber device category (override in subclasses).
    """
    super().__init__(category, entity_data)
    self.current_position = 0
    self._open_rate: str | None = None
    self._tilt_position: int | None = None

min_position class-attribute instance-attribute

min_position = 0

Minimum allowed position (0-100%).

max_position class-attribute instance-attribute

max_position = 100

Maximum allowed position (0-100%).

battery_level class-attribute instance-attribute

battery_level = 0

Battery level percentage (0-100%).

current_position class-attribute instance-attribute

current_position = 0

Current cover position (0-100%).

fill_by_ha_state

fill_by_ha_state(ha_state)

Update state from Home Assistant data.

Battery level, tilt position and signal strength are parsed via :class:AttrSpec. current_position and open_rate have custom fallback / mapping logic and stay imperative.

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/curtain.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Update state from Home Assistant data.

    Battery level, tilt position and signal strength are parsed via
    :class:`AttrSpec`.  ``current_position`` and ``open_rate`` have
    custom fallback / mapping logic and stay imperative.

    Args:
        ha_state: HA state dict with 'state' and 'attributes' keys.
    """
    super().fill_by_ha_state(ha_state)
    attrs = ha_state.get("attributes", {})
    self._apply_attr_specs(attrs)
    self.current_position = self._parse_current_position(attrs)
    self._open_rate = self._parse_open_rate(attrs)

create_allowed_values_list

create_allowed_values_list()

Return allowed values for open_set, open_percentage, and open_rate features.

Source code in custom_components/sber_mqtt_bridge/devices/curtain.py
def create_allowed_values_list(self) -> dict[str, dict]:
    """Return allowed values for open_set, open_percentage, and open_rate features."""
    allowed: dict[str, dict] = {
        "open_set": {
            "type": "ENUM",
            "enum_values": {"values": ["open", "close", "stop"]},
        },
        "open_percentage": {
            "type": "INTEGER",
            "integer_values": {"min": "0", "max": "100", "step": "1"},
        },
    }
    # open_rate is read-only (HA cover has no set_speed service)
    # light_transmission_percentage maps to tilt — handled via open_percentage
    return allowed

to_sber_current_state

to_sber_current_state()

Build Sber current state payload with position, open state, and signal.

Per Sber C2C specification, integer_value is serialized as a string.

Returns:

Type Description
dict[str, dict]

Dict mapping entity_id to its Sber state representation.

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

    Per Sber C2C specification, ``integer_value`` is serialized as a string.

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

    states = [
        make_state(SberFeature.ONLINE, make_bool_value(True)),
    ]

    states.append(
        make_state(SberFeature.OPEN_PERCENTAGE, make_integer_value(self._convert_position(self.current_position)))
    )

    # Enforce consistency: open_state must match open_percentage
    sber_pos = self._convert_position(self.current_position)
    # Sber supports: open, close, opening, closing
    state_map = {"open": "open", "opening": "opening", "closed": "close", "closing": "closing"}
    open_state = state_map.get(self.state, "close" if sber_pos == 0 else "open")
    # Force alignment for stable states: percentage > 0 must be 'open'; 0 must be 'close'
    if self.state not in ("opening", "closing"):
        if sber_pos > 0 and open_state == "close":
            open_state = "open"
        elif sber_pos == 0 and open_state == "open":
            open_state = "close"
    states.append(make_state(SberFeature.OPEN_STATE, make_enum_value(open_state)))

    self._append_battery_signal_states(states)
    if self._open_rate is not None:
        states.append(make_state(SberFeature.OPEN_RATE, make_enum_value(self._open_rate)))
    if self._tilt_position is not None:
        states.append(
            make_state(SberFeature.LIGHT_TRANSMISSION_PERCENTAGE, make_integer_value(self._tilt_position))
        )

    return {self.entity_id: {"states": states}}

WindowBlindEntity

Оконные жалюзи с управлением наклоном.

Sber Window Blind entity -- maps HA blind/shade/shutter covers to Sber window_blind.

WINDOW_BLIND_CATEGORY module-attribute

WINDOW_BLIND_CATEGORY = 'window_blind'

Sber device category for window blind/shade/shutter entities.

WindowBlindEntity

WindowBlindEntity(entity_data)

Bases: CurtainEntity

Sber window blind entity for blind/shade/shutter devices.

Inherits all curtain behavior (position control, open/close/stop) but registers under the Sber 'window_blind' category.

Initialize window blind 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/window_blind.py
def __init__(self, entity_data: dict) -> None:
    """Initialize window blind entity.

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

GateEntity

Ворота/калитка.

Sber Gate entity -- maps HA cover (gate/garage_door) entities to Sber gate category.

GATE_ENTITY_CATEGORY module-attribute

GATE_ENTITY_CATEGORY = 'gate'

Sber device category for gate/garage door entities.

GateEntity

GateEntity(entity_data)

Bases: CurtainEntity

Sber gate entity for gate/garage door control.

Inherits all curtain functionality (position, open/close/stop) but uses the Sber 'gate' category instead of 'curtain'.

Maps HA cover entities with device_class 'gate' or 'garage_door'.

Initialize gate 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/gate.py
def __init__(self, entity_data: dict) -> None:
    """Initialize gate entity.

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