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

Медиа

TVEntity

Телевизор: управление питанием, громкостью, каналами, источником.

Sber TV entity -- maps HA media_player entities to Sber tv category.

Supports on/off, volume, mute, source selection, channel switching, navigation direction, and custom key commands.

TV_CATEGORY module-attribute

TV_CATEGORY = 'tv'

Sber device category for TV entities.

TvEntity

TvEntity(entity_data)

Bases: BaseEntity

Sber TV entity for television and media player devices.

Maps HA media_player entities to the Sber 'tv' category with support for: - On/off control - Volume level (Sber 0-100 integer, HA 0.0-1.0 float) - Mute toggle - Source (input) selection - Channel switching (+/-) - Navigation direction (up/down/left/right/ok)

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

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(TV_CATEGORY, entity_data)
    self.current_state: bool = False
    self._volume: int = 0
    self._is_muted: bool = False
    self._source: str | None = None
    self._source_list: list[str] = []
    self._media_content_id: str | None = None

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update TV attributes.

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/tv.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update TV attributes.

    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_state = ha_state.get("state") not in ("off", "standby", "unavailable", "unknown")

create_allowed_values_list

create_allowed_values_list()

Build allowed values map for TV features.

Per Sber TV reference, only source needs explicit allowed_values (instance-specific source list). All other TV features (volume_int, channel, direction, etc.) use Sber cloud defaults and MUST NOT be overridden — sending extra keys causes silent device rejection.

Returns:

Type Description
dict[str, dict]

Dict mapping feature key to its allowed values descriptor.

Source code in custom_components/sber_mqtt_bridge/devices/tv.py
def create_allowed_values_list(self) -> dict[str, dict]:
    """Build allowed values map for TV features.

    Per Sber TV reference, only ``source`` needs explicit allowed_values
    (instance-specific source list).  All other TV features (volume_int,
    channel, direction, etc.) use Sber cloud defaults and MUST NOT be
    overridden — sending extra keys causes silent device rejection.

    Returns:
        Dict mapping feature key to its allowed values descriptor.
    """
    allowed: dict[str, dict] = {}
    if self._source_list:
        allowed["source"] = {
            "type": "ENUM",
            "enum_values": {"values": self._source_list},
        }
    return allowed

to_sber_current_state

to_sber_current_state()

Build Sber current state payload with TV attributes.

Returns:

Type Description
dict[str, dict]

Dict mapping entity_id to its Sber state representation.

Source code in custom_components/sber_mqtt_bridge/devices/tv.py
def to_sber_current_state(self) -> dict[str, dict]:
    """Build Sber current state payload with TV attributes.

    Returns:
        Dict mapping entity_id to its Sber state representation.
    """
    states = [
        make_state(SberFeature.ONLINE, make_bool_value(self._is_online)),
        make_state(SberFeature.ON_OFF, make_bool_value(self.current_state)),
        make_state(SberFeature.VOLUME_INT, make_integer_value(self._volume)),
        make_state(SberFeature.MUTE, make_bool_value(self._is_muted)),
    ]
    if self._source:
        states.append(make_state(SberFeature.SOURCE, make_enum_value(self._source)))
    return {self.entity_id: {"states": states}}

IntercomEntity

Домофон.

Sber Intercom entity -- minimal implementation for intercom devices.

Available only via type override (sber_category: intercom). Supports on/off control and read-only call/unlock features from HA attributes.

INTERCOM_CATEGORY module-attribute

INTERCOM_CATEGORY = 'intercom'

Sber device category for intercom entities.

IntercomEntity

IntercomEntity(entity_data)

Bases: OnOffEntity

Sber intercom entity for door intercom devices.

Maps to the Sber 'intercom' category. Available only via type override since there is no standard HA intercom domain.

Supports: - On/off control (inherited from OnOffEntity) - Read-only features from HA attributes: incoming_call, reject_call, unlock

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

    Args:
        entity_data: HA entity registry dict containing entity metadata.
    """
    super().__init__(INTERCOM_CATEGORY, entity_data)
    self._incoming_call: bool = False
    self._reject_call: bool = False
    self._unlock: bool = False

fill_by_ha_state

fill_by_ha_state(ha_state)

Parse HA state and update intercom attributes.

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/intercom.py
def fill_by_ha_state(self, ha_state: dict) -> None:
    """Parse HA state and update intercom attributes.

    Args:
        ha_state: HA state dict with 'state' and 'attributes' keys.
    """
    super().fill_by_ha_state(ha_state)
    attrs = ha_state.get("attributes", {})
    self._incoming_call = bool(attrs.get("incoming_call", False))
    self._reject_call = bool(attrs.get("reject_call", False))
    self._unlock = bool(attrs.get("unlock", False))

to_sber_current_state

to_sber_current_state()

Build Sber current state payload with intercom attributes.

Returns:

Type Description
dict[str, dict]

Dict mapping entity_id to its Sber state representation.

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

    Returns:
        Dict mapping entity_id to its Sber state representation.
    """
    base = super().to_sber_current_state()
    states = base[self.entity_id]["states"]
    states.extend(
        [
            make_state(SberFeature.INCOMING_CALL, make_bool_value(self._incoming_call)),
            make_state(SberFeature.REJECT_CALL, make_bool_value(self._reject_call)),
            make_state(SberFeature.UNLOCK, make_bool_value(self._unlock)),
        ]
    )
    return base