Debian Codegraph @

src/adguardhome/parental.py

raw
1 """Asynchronous Python client for the AdGuard Home API."""
2
3 from __future__ import annotations
4
5 from dataclasses import dataclass
6 from typing import TYPE_CHECKING
7
8 from .exceptions import AdGuardHomeError
9
10 if TYPE_CHECKING:
11 from . import AdGuardHome
12
13
14 @dataclass
15 class AdGuardHomeParental:
16 """Controls AdGuard Home parental control."""
17
18 adguard: AdGuardHome
19
20 async def enabled(self) -> bool:
21 """Return if AdGuard Home parental control is enabled or not.
22
23 Returns
24 -------
25 The current state of the AdGuard Home parental control.
26
27 """
28 response = await self.adguard.request("parental/status")
29 return response["enabled"]
30
31 async def enable(self) -> None:
32 """Enable AdGuard Home parental control.
33
34 Raises
35 ------
36 AdGuardHomeError: If enabling parental control failed.
37
38 """
39 try:
40 await self.adguard.request("parental/enable", method="POST")
41 except AdGuardHomeError as exception:
42 msg = "Enabling AdGuard Home parental control failed"
43 raise AdGuardHomeError(msg) from exception
44
45 async def disable(self) -> None:
46 """Disable AdGuard Home parental control.
47
48 Raises
49 ------
50 AdGuardHomeError: If disabling parental control failed.
51
52 """
53 try:
54 await self.adguard.request("parental/disable", method="POST")
55 except AdGuardHomeError as exception:
56 msg = "Disabling AdGuard Home parental control failed"
57 raise AdGuardHomeError(msg) from exception