"""Services for AdGuard Control Hub integration.""" import logging from homeassistant.core import HomeAssistant from .api import AdGuardHomeAPI _LOGGER = logging.getLogger(__name__) async def async_register_services(hass: HomeAssistant, api: AdGuardHomeAPI) -> None: """Register integration services.""" async def emergency_unblock_service(call): """Emergency unblock service.""" duration = call.data.get("duration", 300) clients = call.data.get("clients", ["all"]) try: if "all" in clients: await api.set_protection(False) _LOGGER.info("Emergency unblock activated globally for %d seconds", duration) else: _LOGGER.info("Emergency unblock activated for clients: %s", clients) except Exception as err: _LOGGER.error("Failed to execute emergency unblock: %s", err) raise # Register emergency unblock service hass.services.async_register( "adguard_hub", "emergency_unblock", emergency_unblock_service ) _LOGGER.info("AdGuard Control Hub services registered") async def async_unregister_services(hass: HomeAssistant) -> None: """Unregister integration services.""" hass.services.async_remove("adguard_hub", "emergency_unblock") _LOGGER.info("AdGuard Control Hub services unregistered")