diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 81ea135b..4c1a3b93 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -336,7 +336,7 @@ class SmartDevice: request_list = [] est_response_size = 1024 if "system" in req else 0 - for module_name, module in self.modules.items(): + for module in self.modules.values(): if not module.is_supported: _LOGGER.debug("Module %s not supported, skipping" % module) continue @@ -356,7 +356,11 @@ class SmartDevice: await self.protocol.query(request) for request in request_list if request ] - update: Dict = {} + # Preserve the last update and merge + # responses on top of it so we remember + # which modules are not supported, otherwise + # every other update will query for them + update: Dict = self._last_update.copy() if self._last_update else {} for response in responses: update = {**update, **response} self._last_update = update diff --git a/kasa/tests/test_smartdevice.py b/kasa/tests/test_smartdevice.py index c70f544b..283fcfef 100644 --- a/kasa/tests/test_smartdevice.py +++ b/kasa/tests/test_smartdevice.py @@ -187,3 +187,10 @@ def test_device_class_ctors(device_class): assert dev.host == host assert dev.port == port assert dev.credentials == credentials + + +async def test_modules_preserved(dev: SmartDevice): + """Make modules that are not being updated are preserved between updates.""" + dev._last_update["some_module_not_being_updated"] = "should_be_kept" + await dev.update() + assert dev._last_update["some_module_not_being_updated"] == "should_be_kept"