Repository: frenck/python-adguardhome (language: python)

Issue:
Callling /control/parental/enable failing with `only content-type application/json is allowed`
# Problem/Motivation

I'm using the AdGuard Home addon in Home Assistant and believe I've traced a bug I'm having to the code in this repository. 

Specifically, the call to /control/parental/enable is failing.

## Expected behavior

Should be able to enable the parental filtering via the API wrapper.

## Actual behavior

Throws an error with: `only content-type application/json is allowed`.

## Steps to reproduce

- pip install adguardhome
- Temporarily configure AdGuard Home Addon in HA to `leave_front_door_open` and set a port (eg 3001) for the Web interface
![image](https://github.com/frenck/python-adguardhome/assets/452393/66604f02-1a11-4179-92be-4001c506fefd)
- Edit the following and change the IP/port to suit your AdGuard Home installation
```python
"""Asynchronous Python client for the AdGuard Home API."""

import asyncio

from adguardhome import AdGuardHome


async def main():
    """Show example how to get status of your AdGuard Home instance."""
    async with AdGuardHome(host="192.168.1.2", port="3001", tls=True, verify_ssl=False) as adguard:
        version = await adguard.version()
        print("AdGuard version:", version)

        await adguard.parental.disable()

        active = await adguard.parental.enabled()
        active = "Yes" if active else "No"
        print("Parental control enabled?", active)

        await adguard.parental.enable()
        active = await adguard.parental.enabled()
        active = "Yes" if active else "No"
        print("Parental control enabled?", active)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
```
- python3 adguard_test.py

## Proposed changes

It appears the AdGuard Home API now enforces a "Content-Type: application/json" for the API when a body is present. The request to /control/parental/enable is adding a body but it's not JSON.

From what I can tell from https://github.com/AdguardTeam/AdGuardHome/blob/master/openapi/openapi.yaml the endpoint doesn't actually expect a body.

The fix is to simply remove the data argument on line 36 of parental.py.



Discussion / hints:

Fix patch:
diff --git a/src/adguardhome/parental.py b/src/adguardhome/parental.py
index 3e6759b5..f7db26ff 100644
--- a/src/adguardhome/parental.py
+++ b/src/adguardhome/parental.py
@@ -32,9 +32,7 @@ async def enable(self) -> None:
             AdGuardHomeError: If enabling parental control failed.
         """
         try:
-            await self.adguard.request(
-                "parental/enable", method="POST", data="sensitivity=TEEN"
-            )
+            await self.adguard.request("parental/enable", method="POST")
         except AdGuardHomeError as exception:
             raise AdGuardHomeError(
                 "Enabling AdGuard Home parental control failed"


Test patch:
diff --git a/tests/test_parental.py b/tests/test_parental.py
index 2c02c399..69e71c9e 100644
--- a/tests/test_parental.py
+++ b/tests/test_parental.py
@@ -41,14 +41,11 @@ async def test_enabled(aresponses):
 async def test_enable(aresponses):
     """Test enabling AdGuard Home parental control."""
     # Handle to run asserts on request in
-    async def response_handler(request):
-        """Response handler for this test."""
-        data = await request.text()
-        assert data == "sensitivity=TEEN"
-        return aresponses.Response(status=200, text="OK")
-
     aresponses.add(
-        "example.com:3000", "/control/parental/enable", "POST", response_handler
+        "example.com:3000",
+        "/control/parental/enable",
+        "POST",
+        aresponses.Response(status=200, text="OK"),
     )
     aresponses.add(
         "example.com:3000",