From 58254caf263e43956eeb96e705e924c0bd4ff905 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sat, 29 Jan 2022 18:04:47 +0100 Subject: [PATCH 1/2] Do not request unsupported modules after the initial update --- kasa/modules/module.py | 8 ++++++++ kasa/smartdevice.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/kasa/modules/module.py b/kasa/modules/module.py index 1f7f3829f..dc4c1bfae 100644 --- a/kasa/modules/module.py +++ b/kasa/modules/module.py @@ -1,5 +1,6 @@ """Base class for all module implementations.""" import collections +import logging from abc import ABC, abstractmethod from typing import TYPE_CHECKING @@ -7,6 +8,9 @@ from kasa import SmartDevice +_LOGGER = logging.getLogger(__name__) + + # TODO: This is used for query construcing def merge(d, u): """Update dict recursively.""" @@ -45,6 +49,10 @@ def data(self): @property def is_supported(self) -> bool: """Return whether the module is supported by the device.""" + if self._module not in self._device._last_update: + _LOGGER.debug("Initial update, so consider supported: %s", self._module) + return True + return "err_code" not in self.data def call(self, method, params=None): diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index e06318146..6bcdf8711 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -321,6 +321,9 @@ async def update(self, update_children: bool = True): self.add_module("emeter", Emeter(self, self.emeter_type)) for module in self.modules.values(): + if not module.is_supported: + _LOGGER.info("Module %s not supported, skipping" % module) + continue q = module.query() _LOGGER.debug("Adding query for %s: %s", module, q) req = merge(req, module.query()) From cbe7e0c1445eace43ba8493f76c2f61437595469 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sat, 29 Jan 2022 18:14:08 +0100 Subject: [PATCH 2/2] debugify logging --- kasa/smartdevice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 6bcdf8711..36412e8f8 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -322,7 +322,7 @@ async def update(self, update_children: bool = True): for module in self.modules.values(): if not module.is_supported: - _LOGGER.info("Module %s not supported, skipping" % module) + _LOGGER.debug("Module %s not supported, skipping" % module) continue q = module.query() _LOGGER.debug("Adding query for %s: %s", module, q)