From c0a409b25fe6923ff86950c43a47542f120f5a72 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Thu, 29 Sep 2022 12:13:02 -0400 Subject: [PATCH] No unpack variants for property sets (#3911) --- supervisor/utils/dbus.py | 17 +++++++++++++---- tests/api/test_supervisor.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/supervisor/utils/dbus.py b/supervisor/utils/dbus.py index be39b2175..998784dcb 100644 --- a/supervisor/utils/dbus.py +++ b/supervisor/utils/dbus.py @@ -90,9 +90,11 @@ class DBus: proxy_interface.path, ) try: - return await getattr(proxy_interface, method)( - *args, unpack_variants=unpack_variants - ) + if unpack_variants: + return await getattr(proxy_interface, method)( + *args, unpack_variants=True + ) + return await getattr(proxy_interface, method)(*args) except DBusError as err: raise DBus.from_dbus_error(err) @@ -299,7 +301,7 @@ class DBusCallWrapper: return _off_signal - if dbus_type in ["call", "get", "set"]: + if dbus_type in ["call", "get"]: def _method_wrapper(*args, unpack_variants: bool = True) -> Awaitable: return DBus.call_dbus( @@ -308,6 +310,13 @@ class DBusCallWrapper: return _method_wrapper + elif dbus_type == "set": + + def _set_wrapper(*args) -> Awaitable: + return DBus.call_dbus(self._proxy, name, *args, unpack_variants=False) + + return _set_wrapper + # Didn't reach the dbus call yet, just happened to hit another interface. Return a wrapper return DBusCallWrapper(self.dbus, f"{self.interface}.{name}") diff --git a/tests/api/test_supervisor.py b/tests/api/test_supervisor.py index 217a14128..88e904087 100644 --- a/tests/api/test_supervisor.py +++ b/tests/api/test_supervisor.py @@ -1,5 +1,6 @@ """Test Supervisor API.""" # pylint: disable=protected-access +import asyncio from unittest.mock import patch from aiohttp.test_utils import TestClient @@ -114,3 +115,17 @@ async def test_api_supervisor_options_auto_update( assert response.status == 200 assert coresys.updater.auto_update is False + + +async def test_api_supervisor_options_diagnostics( + api_client: TestClient, coresys: CoreSys, dbus: list[str] +): + """Test changing diagnostics.""" + await coresys.dbus.agent.connect(coresys.dbus.bus) + dbus.clear() + + response = await api_client.post("/supervisor/options", json={"diagnostics": True}) + await asyncio.sleep(0) + + assert response.status == 200 + assert dbus == ["/io/hass/os-io.hass.os.Diagnostics"]