fix: fixes
Some checks failed
🧪 Integration Testing / 🔧 Test Integration (2025.9.4, 3.13) (push) Failing after 19s
🛡️ Code Quality & Security Check / 🔍 Code Quality Analysis (push) Failing after 19s

Signed-off-by: Rafal Zielinski <sq4ind@gmail.com>
This commit is contained in:
2025-09-28 15:46:21 +01:00
parent 4553eb454a
commit e0edf6f865
11 changed files with 196 additions and 695 deletions

View File

@@ -69,18 +69,6 @@ class AdGuardProtectionSwitch(AdGuardBaseSwitch):
"""Return the icon for the switch."""
return ICON_PROTECTION if self.is_on else ICON_PROTECTION_OFF
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return additional state attributes."""
status = self.coordinator.protection_status
stats = self.coordinator.statistics
return {
"dns_port": status.get("dns_port", "N/A"),
"queries_today": stats.get("num_dns_queries_today", 0),
"blocked_today": stats.get("num_blocked_filtering_today", 0),
"version": status.get("version", "N/A"),
}
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on AdGuard protection."""
try:
@@ -124,50 +112,18 @@ class AdGuardClientSwitch(AdGuardBaseSwitch):
client = self.coordinator.clients.get(self.client_name, {})
return client.get("filtering_enabled", True)
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return additional state attributes."""
client = self.coordinator.clients.get(self.client_name, {})
blocked_services = client.get("blocked_services", {})
if isinstance(blocked_services, dict):
service_ids = blocked_services.get("ids", [])
else:
service_ids = blocked_services if blocked_services else []
return {
"client_ids": client.get("ids", []),
"mac": client.get("mac", ""),
"use_global_settings": client.get("use_global_settings", True),
"safebrowsing_enabled": client.get("safebrowsing_enabled", False),
"parental_enabled": client.get("parental_enabled", False),
"safesearch_enabled": client.get("safesearch_enabled", False),
"blocked_services": service_ids,
"blocked_services_count": len(service_ids),
}
async def async_turn_on(self, **kwargs: Any) -> None:
"""Enable protection for this client."""
try:
# Get current client data
client = await self.api.get_client_by_name(self.client_name)
if not client:
_LOGGER.error("Client %s not found", self.client_name)
return
# Update client with filtering enabled
update_data = {
"name": self.client_name,
"data": {
**client,
"filtering_enabled": True,
if client:
update_data = {
"name": self.client_name,
"data": {**client, "filtering_enabled": True}
}
}
await self.api.update_client(update_data)
await self.coordinator.async_request_refresh()
_LOGGER.info("Enabled protection for client %s", self.client_name)
await self.api.update_client(update_data)
await self.coordinator.async_request_refresh()
_LOGGER.info("Enabled protection for client %s", self.client_name)
except Exception as err:
_LOGGER.error("Failed to enable protection for %s: %s", self.client_name, err)
raise
@@ -175,25 +131,15 @@ class AdGuardClientSwitch(AdGuardBaseSwitch):
async def async_turn_off(self, **kwargs: Any) -> None:
"""Disable protection for this client."""
try:
# Get current client data
client = await self.api.get_client_by_name(self.client_name)
if not client:
_LOGGER.error("Client %s not found", self.client_name)
return
# Update client with filtering disabled
update_data = {
"name": self.client_name,
"data": {
**client,
"filtering_enabled": False,
if client:
update_data = {
"name": self.client_name,
"data": {**client, "filtering_enabled": False}
}
}
await self.api.update_client(update_data)
await self.coordinator.async_request_refresh()
_LOGGER.info("Disabled protection for client %s", self.client_name)
await self.api.update_client(update_data)
await self.coordinator.async_request_refresh()
_LOGGER.info("Disabled protection for client %s", self.client_name)
except Exception as err:
_LOGGER.error("Failed to disable protection for %s: %s", self.client_name, err)
raise