From 81e2685605bba07fecb0b8172258dffaea330bed Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Tue, 1 Oct 2024 12:47:36 +0100 Subject: [PATCH] Send empty dictionary instead of null for iot queries (#1145) --- devtools/dump_devinfo.py | 4 ++-- kasa/device_factory.py | 4 ++-- kasa/discover.py | 4 ++-- kasa/iot/iotdevice.py | 2 ++ kasa/klaptransport.py | 1 - 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/devtools/dump_devinfo.py b/devtools/dump_devinfo.py index 34a06787..8ca39d03 100644 --- a/devtools/dump_devinfo.py +++ b/devtools/dump_devinfo.py @@ -285,7 +285,7 @@ async def get_legacy_fixture(device): try: click.echo(f"Testing {test_call}..", nl=False) info = await device.protocol.query( - {test_call.module: {test_call.method: None}} + {test_call.module: {test_call.method: {}}} ) resp = info[test_call.module] except Exception as ex: @@ -302,7 +302,7 @@ async def get_legacy_fixture(device): final_query = defaultdict(defaultdict) final = defaultdict(defaultdict) for succ, resp in successes: - final_query[succ.module][succ.method] = None + final_query[succ.module][succ.method] = {} final[succ.module][succ.method] = resp final = default_to_regular(final) diff --git a/kasa/device_factory.py b/kasa/device_factory.py index 1bb6fc4a..a124bb4c 100755 --- a/kasa/device_factory.py +++ b/kasa/device_factory.py @@ -32,8 +32,8 @@ from .xortransport import XorTransport _LOGGER = logging.getLogger(__name__) -GET_SYSINFO_QUERY = { - "system": {"get_sysinfo": None}, +GET_SYSINFO_QUERY: dict[str, dict[str, dict]] = { + "system": {"get_sysinfo": {}}, } diff --git a/kasa/discover.py b/kasa/discover.py index b541dd7a..a1bc28a3 100755 --- a/kasa/discover.py +++ b/kasa/discover.py @@ -296,8 +296,8 @@ class Discover: DISCOVERY_PORT = 9999 - DISCOVERY_QUERY = { - "system": {"get_sysinfo": None}, + DISCOVERY_QUERY: dict[str, dict[str, dict]] = { + "system": {"get_sysinfo": {}}, } DISCOVERY_PORT_2 = 20002 diff --git a/kasa/iot/iotdevice.py b/kasa/iot/iotdevice.py index 3986c001..2959612f 100755 --- a/kasa/iot/iotdevice.py +++ b/kasa/iot/iotdevice.py @@ -207,6 +207,8 @@ class IotDevice(Device): def _create_request( self, target: str, cmd: str, arg: dict | None = None, child_ids=None ): + if arg is None: + arg = {} request: dict[str, Any] = {target: {cmd: arg}} if child_ids is not None: request = {"context": {"child_ids": child_ids}, target: {cmd: arg}} diff --git a/kasa/klaptransport.py b/kasa/klaptransport.py index 8e22dec0..02e0b2b7 100644 --- a/kasa/klaptransport.py +++ b/kasa/klaptransport.py @@ -88,7 +88,6 @@ class KlapTransport(BaseTransport): """ DEFAULT_PORT: int = 80 - DISCOVERY_QUERY = {"system": {"get_sysinfo": None}} SESSION_COOKIE_NAME = "TP_SESSIONID" TIMEOUT_COOKIE_NAME = "TIMEOUT"