@@ -26,10 +26,6 @@ async def async_setup_entry(
|
||||
|
||||
entities = [
|
||||
AdGuardProtectionBinarySensor(coordinator, api),
|
||||
AdGuardFilteringBinarySensor(coordinator, api),
|
||||
AdGuardSafeBrowsingBinarySensor(coordinator, api),
|
||||
AdGuardParentalControlBinarySensor(coordinator, api),
|
||||
AdGuardSafeSearchBinarySensor(coordinator, api),
|
||||
]
|
||||
|
||||
async_add_entities(entities)
|
||||
@@ -76,91 +72,6 @@ class AdGuardProtectionBinarySensor(AdGuardBaseBinarySensor):
|
||||
status = self.coordinator.protection_status
|
||||
return {
|
||||
"dns_port": status.get("dns_port", "N/A"),
|
||||
"http_port": status.get("http_port", "N/A"),
|
||||
"version": status.get("version", "N/A"),
|
||||
"running": status.get("running", False),
|
||||
}
|
||||
|
||||
|
||||
class AdGuardFilteringBinarySensor(AdGuardBaseBinarySensor):
|
||||
"""Binary sensor to show DNS filtering status."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the binary sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_filtering_enabled"
|
||||
self._attr_name = "AdGuard DNS Filtering"
|
||||
self._attr_device_class = BinarySensorDeviceClass.RUNNING
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if DNS filtering is enabled."""
|
||||
return self.coordinator.protection_status.get("filtering_enabled", False)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon for the binary sensor."""
|
||||
return "mdi:dns" if self.is_on else "mdi:dns-off"
|
||||
|
||||
|
||||
class AdGuardSafeBrowsingBinarySensor(AdGuardBaseBinarySensor):
|
||||
"""Binary sensor to show Safe Browsing status."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the binary sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_safebrowsing_enabled"
|
||||
self._attr_name = "AdGuard Safe Browsing"
|
||||
self._attr_device_class = BinarySensorDeviceClass.SAFETY
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if Safe Browsing is enabled."""
|
||||
return self.coordinator.protection_status.get("safebrowsing_enabled", False)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon for the binary sensor."""
|
||||
return "mdi:security" if self.is_on else "mdi:security-off"
|
||||
|
||||
|
||||
class AdGuardParentalControlBinarySensor(AdGuardBaseBinarySensor):
|
||||
"""Binary sensor to show Parental Control status."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the binary sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_parental_enabled"
|
||||
self._attr_name = "AdGuard Parental Control"
|
||||
self._attr_device_class = BinarySensorDeviceClass.SAFETY
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if Parental Control is enabled."""
|
||||
return self.coordinator.protection_status.get("parental_enabled", False)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon for the binary sensor."""
|
||||
return "mdi:account-child" if self.is_on else "mdi:account-child-outline"
|
||||
|
||||
|
||||
class AdGuardSafeSearchBinarySensor(AdGuardBaseBinarySensor):
|
||||
"""Binary sensor to show Safe Search status."""
|
||||
|
||||
def __init__(self, coordinator: AdGuardControlHubCoordinator, api: AdGuardHomeAPI):
|
||||
"""Initialize the binary sensor."""
|
||||
super().__init__(coordinator, api)
|
||||
self._attr_unique_id = f"{api.host}_{api.port}_safesearch_enabled"
|
||||
self._attr_name = "AdGuard Safe Search"
|
||||
self._attr_device_class = BinarySensorDeviceClass.SAFETY
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if Safe Search is enabled."""
|
||||
return self.coordinator.protection_status.get("safesearch_enabled", False)
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon for the binary sensor."""
|
||||
return "mdi:search-web" if self.is_on else "mdi:web-off"
|
||||
|
Reference in New Issue
Block a user