@@ -24,11 +24,9 @@ async def async_setup_entry(
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
|
||||
api = hass.data[DOMAIN][config_entry.entry_id]["api"]
|
||||
|
||||
entities = []
|
||||
# Add global protection switch
|
||||
entities.append(AdGuardProtectionSwitch(coordinator, api))
|
||||
entities = [AdGuardProtectionSwitch(coordinator, api)]
|
||||
|
||||
# Add client switches
|
||||
# Add client switches if clients exist
|
||||
for client_name in coordinator.clients.keys():
|
||||
entities.append(AdGuardClientSwitch(coordinator, api, client_name))
|
||||
|
||||
@@ -74,7 +72,6 @@ class AdGuardProtectionSwitch(AdGuardBaseSwitch):
|
||||
try:
|
||||
await self.api.set_protection(True)
|
||||
await self.coordinator.async_request_refresh()
|
||||
_LOGGER.info("AdGuard protection enabled")
|
||||
except Exception as err:
|
||||
_LOGGER.error("Failed to enable AdGuard protection: %s", err)
|
||||
raise
|
||||
@@ -84,7 +81,6 @@ class AdGuardProtectionSwitch(AdGuardBaseSwitch):
|
||||
try:
|
||||
await self.api.set_protection(False)
|
||||
await self.coordinator.async_request_refresh()
|
||||
_LOGGER.info("AdGuard protection disabled")
|
||||
except Exception as err:
|
||||
_LOGGER.error("Failed to disable AdGuard protection: %s", err)
|
||||
raise
|
||||
@@ -123,7 +119,6 @@ class AdGuardClientSwitch(AdGuardBaseSwitch):
|
||||
}
|
||||
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
|
||||
@@ -139,7 +134,6 @@ class AdGuardClientSwitch(AdGuardBaseSwitch):
|
||||
}
|
||||
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
|
||||
|
Reference in New Issue
Block a user