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

Медиа

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.

SOURCE_VALUES module-attribute

SOURCE_VALUES = FEATURE_ENUM_VALUES['source']

Every input Sber's source function documents.

hdmi1hdmi3, tv, av, content, screencast plus the relative + / -. Home Assistant names the same inputs in prose ("HDMI 1", "Станция"), so the two are reconciled through :mod:.utils.enum_matcher rather than published as-is.

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, translated between HA's prose input names and Sber's closed source vocabulary (:data:SOURCE_VALUES) - Channel switching (+/-) - Navigation direction (up/down/left/right/ok)

Command handlers address the entity in its own HA domain (:meth:get_entity_domain) rather than a hard-coded media_player: tv is an overridable category, so a switch.tv_power promoted to tv by a user type override would otherwise be driven with media_player.turn_on — a call HA cannot route, silently dropping every Sber command. For a media_player.* entity — the only domain the category maps to by itself — the emitted calls are unchanged.

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
    self._source_to_sber: dict[str, str] = {}
    self._source_to_ha: dict[str, str] = {}

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._source_to_sber = map_ha_values(self._source_list, SOURCE_VALUES)
    self._source_to_ha = invert_value_map(self._source_to_sber)
    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.

The declared values are the Sber ones this TV can actually reach (hdmi1, tv, …), never the HA input names: the app renders exactly what is declared and then sends it back as a command, so a label outside :data:SOURCE_VALUES would be a control that cannot work.

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.

    The declared values are the *Sber* ones this TV can actually reach
    (``hdmi1``, ``tv``, …), never the HA input names: the app renders
    exactly what is declared and then sends it back as a command, so a
    label outside :data:`SOURCE_VALUES` would be a control that cannot
    work.

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

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

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))