Initial commit
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.11) (push) Successful in 2m11s
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.12) (push) Successful in 2m2s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.11) (push) Successful in 1m4s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.12) (push) Successful in 1m19s
🛡️ Code Quality & Security Check / 🔍 Code Quality Analysis (push) Failing after 56s
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.11) (push) Successful in 2m11s
🧪 Integration Testing / 🔧 Test Integration (2023.12.0, 3.12) (push) Successful in 2m2s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.11) (push) Successful in 1m4s
🧪 Integration Testing / 🔧 Test Integration (2024.1.0, 3.12) (push) Successful in 1m19s
🛡️ Code Quality & Security Check / 🔍 Code Quality Analysis (push) Failing after 56s
Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
38
custom_components/adguard_hub/services.py
Normal file
38
custom_components/adguard_hub/services.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""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")
|
Reference in New Issue
Block a user