Skip to content

Commit

Permalink
feat: add disable protection for a specific duration
Browse files Browse the repository at this point in the history
Fixes frenck#1030

Signed-off-by: Romain Beuque <[email protected]>
  • Loading branch information
rbeuque74 committed May 3, 2024
1 parent 026625d commit e625d71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/adguardhome/adguardhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,17 @@ async def enable_protection(self) -> None:
"""
try:
await self.request(
"dns_config",
"protection",
method="POST",
json_data={"protection_enabled": True},
json_data={"enabled": True},
)
except AdGuardHomeError as exception:
msg = "Failed enabling AdGuard Home protection"
raise AdGuardHomeError(msg) from exception

async def disable_protection(self) -> None:
async def disable_protection(
self, pause_duration_miliseconds: int | None = None
) -> None:
"""Disable AdGuard Home protection.
Raises
Expand All @@ -219,10 +221,13 @@ async def disable_protection(self) -> None:
"""
try:
data: dict[str, Any] = {"enabled": False}
if not pause_duration_miliseconds:
data["duration"] = pause_duration_miliseconds
await self.request(
"dns_config",
"protection",
method="POST",
json_data={"protection_enabled": False},
json_data=data,
)
except AdGuardHomeError as exception:
msg = "Failed disabling AdGuard Home protection"
Expand Down
10 changes: 5 additions & 5 deletions tests/test_adguardhome.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ async def test_enable_protection(aresponses: ResponsesMockServer) -> None:
"""Test enabling AdGuard Home protection."""
aresponses.add(
"example.com:3000",
"/control/dns_config",
"/control/protection",
"POST",
aresponses.Response(status=200),
)
aresponses.add(
"example.com:3000",
"/control/dns_config",
"/control/protection",
"POST",
aresponses.Response(status=400),
)
Expand All @@ -277,13 +277,13 @@ async def test_disable_protection(aresponses: ResponsesMockServer) -> None:
"""Test disabling AdGuard Home protection."""
aresponses.add(
"example.com:3000",
"/control/dns_config",
"/control/protection",
"POST",
aresponses.Response(status=200),
)
aresponses.add(
"example.com:3000",
"/control/dns_config",
"/control/protection",
"POST",
aresponses.Response(status=500),
)
Expand All @@ -295,7 +295,7 @@ async def test_disable_protection(aresponses: ResponsesMockServer) -> None:
await adguard.disable_protection()


async def test_verion(aresponses: ResponsesMockServer) -> None:
async def test_version(aresponses: ResponsesMockServer) -> None:
"""Test requesting AdGuard Home instance version."""
aresponses.add(
"example.com:3000",
Expand Down

0 comments on commit e625d71

Please sign in to comment.