Fix every other query tries to fetch known unsupported features (#520)

* Fix every other query tries to fetch known unsupported features

* ensure modules not being updated are preserved
This commit is contained in:
J. Nick Koston 2023-10-05 15:50:54 -05:00 committed by GitHub
parent 84a501bcdc
commit 20b3f7a771
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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

View File

@ -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"