{"record":{"id":"d74517b5a44e3b3d","repo":"home-assistant/core","slug":"connection-closed-d74517","errorCode":"connection_closed","errorMessage":"Connection to the Android TV device is closed","messagePattern":"Connection to the Android TV device is closed","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/androidtv_remote/media_player.py","lineNumber":257,"sourceCode":"            can_play=False,\n            can_expand=True,\n            children=children,\n        )\n\n    async def _send_key_commands(\n        self, key_codes: list[str], delay_secs: float = 0.1\n    ) -> None:\n        \"\"\"Send a key press sequence to Android TV.\n\n        The delay is necessary because device may ignore\n        some commands if we send the sequence without delay.\n        \"\"\"\n        try:\n            for key_code in key_codes:\n                self._api.send_key_command(key_code)\n                await asyncio.sleep(delay_secs)\n        except ConnectionClosed as exc:\n            raise HomeAssistantError(\n                translation_domain=DOMAIN, translation_key=\"connection_closed\"\n            ) from exc\n","sourceCodeStart":239,"sourceCodeEnd":260,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/androidtv_remote/media_player.py#L239-L260","documentation":"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.","triggerScenarios":"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.","commonSituations":"Long channel numbers (3-4 digits) sent right as the TV powers off or the network flaps; consecutive channel changes racing each other.","solutions":["Confirm TV connectivity and retry the channel change once the entity is available.","Reload the integration if the remote session does not self-recover.","In automations, guard channel-change steps on the entity's available state."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not self._api.is_available:\n    return  # avoid starting a doomed digit sequence","typeGuard":null,"tryCatchPattern":"except HomeAssistantError: cancel any pending channel task and re-run the channel change after reconnect; digits may be partially sent.","preventionTips":["Avoid rapid consecutive channel changes; the task cancellation path exists for this.","Gate channel-change automations on entity availability."],"tags":["remote-protocol","connection","androidtv","media-player"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}