home-assistant/core · error · HomeAssistantError

connection_closed

connection_closed

Error message

Connection to the Android TV device is closed

What it means

Raised as HomeAssistantError (connection_closed) when a digit-sequence key send (_send_key_commands) hits ConnectionClosed partway through: the loop sends one digit at a time with a 0.1s delay, and if the remote session closes mid-sequence the exception from api.send_key_command is wrapped. Distinct from 189 in that partial digits may already have been sent.

Source

Thrown at homeassistant/components/androidtv_remote/media_player.py:257

            can_play=False,
            can_expand=True,
            children=children,
        )

    async def _send_key_commands(
        self, key_codes: list[str], delay_secs: float = 0.1
    ) -> None:
        """Send a key press sequence to Android TV.

        The delay is necessary because device may ignore
        some commands if we send the sequence without delay.
        """
        try:
            for key_code in key_codes:
                self._api.send_key_command(key_code)
                await asyncio.sleep(delay_secs)
        except ConnectionClosed as exc:
            raise HomeAssistantError(
                translation_domain=DOMAIN, translation_key="connection_closed"
            ) from exc

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Confirm TV connectivity and retry the channel change once the entity is available.
  2. Reload the integration if the remote session does not self-recover.
  3. In automations, guard channel-change steps on the entity's available state.
Defensive patterns

Strategy: try-catch

Validate before calling

if not self._api.is_available:
    return  # avoid starting a doomed digit sequence

Try / catch

except HomeAssistantError: cancel any pending channel task and re-run the channel change after reconnect; digits may be partially sent.

Prevention

When it happens

Trigger: play_media(channel) with a multi-digit number while the TV connection drops mid-send, e.g. TV entering standby or Wi-Fi failing between digit key presses; also when the pending channel-set task is awaited after a session loss.

Common situations: Long channel numbers (3-4 digits) sent right as the TV powers off or the network flaps; consecutive channel changes racing each other.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/d74517b5a44e3b3d. Report an issue: GitHub.