{"record":{"id":"a70054e6bb950f0f","repo":"home-assistant/core","slug":"error-while-turn-off","errorCode":"error_while_turn_off","errorMessage":"An error occurred while turning off AdGuard Home switch.","messagePattern":"An error occurred while turning off AdGuard Home switch\\.","errorType":"exception","errorClass":"HomeAssistantError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/adguard/switch.py","lineNumber":123,"sourceCode":"        self.entity_description = description\n        self._attr_unique_id = \"_\".join(  # pylint: disable=home-assistant-entity-unique-id-redundant-domain,home-assistant-entity-unique-id-redundant-platform\n            [\n                DOMAIN,\n                self.adguard.host,\n                str(self.adguard.port),\n                \"switch\",\n                description.key,\n            ]\n        )\n\n    @override\n    async def async_turn_off(self, **kwargs: Any) -> None:\n        \"\"\"Turn off the switch.\"\"\"\n        try:\n            await self.entity_description.turn_off_fn(self.adguard)()\n        except AdGuardHomeError as err:\n            self._attr_available = False\n            raise HomeAssistantError(\n                translation_domain=DOMAIN,\n                translation_key=\"error_while_turn_off\",\n            ) from err\n\n    @override\n    async def async_turn_on(self, **kwargs: Any) -> None:\n        \"\"\"Turn on the switch.\"\"\"\n        try:\n            await self.entity_description.turn_on_fn(self.adguard)()\n        except AdGuardHomeError as err:\n            self._attr_available = False\n            raise HomeAssistantError(\n                translation_domain=DOMAIN,\n                translation_key=\"error_while_turn_on\",\n            ) from err\n\n    @override\n    async def _adguard_update(self) -> None:","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/adguard/switch.py#L105-L141","documentation":"HomeAssistantError with translation_key error_while_turn_off, raised by AdGuardSwitch.async_turn_off when entity_description.turn_off_fn(self.adguard)() raises AdGuardHomeError (base class of the adguard library's exceptions). The entity sets _attr_available = False before raising, so the switch shows unavailable until a later successful poll.","triggerScenarios":"Toggling any AdGuard switch entity (protection, filtering, parental control, safe search, query log...) while the AdGuard Home server is unreachable, returns an HTTP error, or the API call (e.g. adguard.filtering.set_protection or the per-switch setter) fails.","commonSituations":"AdGuard Home server down or restarting, wrong host/port/credentials after server migration, TLS verification issues with a self-signed cert, or AdGuard Home version incompatibility removing/renaming an API endpoint.","solutions":["Verify the AdGuard Home web UI loads at the configured host:port and the API credentials (username/password or user-defined token) are current.","Reload the AdGuard Home config entry so the client re-authenticates, then retry the switch command.","Check the Home Assistant log for the chained AdGuardHomeError ('from err') to see the exact HTTP status; 401/403 means credentials, 5xx means server-side trouble.","If a self-signed certificate is used, ensure verify_ssl and the URL scheme in the entry are consistent (https with proper cert or explicit allow-insecure setting).","Update the adguard library / Home Assistant if a specific switch endpoint broke with a newer AdGuard Home version."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from homeassistant.exceptions import HomeAssistantError\n\nfor attempt in range(3):\n    try:\n        await switch.async_turn_off()\n        break\n    except HomeAssistantError:\n        if attempt == 2:\n            raise\n        await asyncio.sleep(5)  # AdGuard server may be restarting","preventionTips":["Watch the switch entity's availability — the integration marks it unavailable on failure and the next successful poll restores it.","Keep AdGuard Home reachable and credentials current so turn_off_fn never hits AdGuardHomeError.","For scripted toggles, retry with backoff to ride out AdGuard restarts."],"tags":["homeassistant","adguard","switch","api-error"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}