From 4ae9a32b74b43ccf564679d5d977bb9eb5915e32 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Wed, 26 Apr 2023 16:59:07 -0600 Subject: [PATCH 1/9] commented out modules that break --- kasa/smartbulb.py | 6 +- kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json | 88 +++++++++++++++++++ 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json diff --git a/kasa/smartbulb.py b/kasa/smartbulb.py index b28edab1b..40a805147 100644 --- a/kasa/smartbulb.py +++ b/kasa/smartbulb.py @@ -204,11 +204,11 @@ def __init__(self, host: str) -> None: self._device_type = DeviceType.Bulb self.add_module("schedule", Schedule(self, "smartlife.iot.common.schedule")) self.add_module("usage", Usage(self, "smartlife.iot.common.schedule")) - self.add_module("antitheft", Antitheft(self, "smartlife.iot.common.anti_theft")) + # self.add_module("antitheft", Antitheft(self, "smartlife.iot.common.anti_theft")) self.add_module("time", Time(self, "smartlife.iot.common.timesetting")) self.add_module("emeter", Emeter(self, self.emeter_type)) - self.add_module("countdown", Countdown(self, "countdown")) - self.add_module("cloud", Cloud(self, "smartlife.iot.common.cloud")) + # self.add_module("countdown", Countdown(self, "countdown")) + # self.add_module("cloud", Cloud(self, "smartlife.iot.common.cloud")) @property # type: ignore @requires_update diff --git a/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json b/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json new file mode 100644 index 000000000..22b210fa9 --- /dev/null +++ b/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json @@ -0,0 +1,88 @@ +{ + "smartlife.iot.common.emeter": { + "get_realtime": { + "err_code": 0, + "power_mw": 10800, + "total_wh": 42 + } + }, + "smartlife.iot.smartbulb.lightingservice": { + "get_light_state": { + "brightness": 100, + "color_temp": 0, + "err_code": 0, + "hue": 0, + "mode": "normal", + "on_off": 1, + "saturation": 0 + } + }, + "system": { + "get_sysinfo": { + "active_mode": "none", + "alias": "Nightstand: Lisa (kasa-bc04)", + "ctrl_protocols": { + "name": "Linkie", + "version": "1.0" + }, + "description": "Smart Wi-Fi LED Bulb with Color Changing", + "dev_state": "normal", + "deviceId": "0000000000000000000000000000000000000000", + "disco_ver": "1.0", + "err_code": 0, + "hwId": "00000000000000000000000000000000", + "hw_ver": "1.20", + "is_color": 1, + "is_dimmable": 1, + "is_factory": false, + "is_variable_color_temp": 1, + "latitude_i": 0, + "light_state": { + "brightness": 100, + "color_temp": 0, + "hue": 0, + "mode": "normal", + "on_off": 1, + "saturation": 0 + }, + "longitude_i": 0, + "mic_mac": "000000000000", + "mic_type": "IOT.SMARTBULB", + "model": "KL125(US)", + "oemId": "00000000000000000000000000000000", + "preferred_state": [ + { + "brightness": 41, + "color_temp": 2700, + "hue": 0, + "index": 0, + "saturation": 0 + }, + { + "brightness": 100, + "color_temp": 0, + "hue": 0, + "index": 1, + "saturation": 100 + }, + { + "brightness": 100, + "color_temp": 0, + "hue": 120, + "index": 2, + "saturation": 100 + }, + { + "brightness": 100, + "color_temp": 0, + "hue": 240, + "index": 3, + "saturation": 100 + } + ], + "rssi": -70, + "status": "new", + "sw_ver": "1.0.7 Build 211009 Rel.172044" + } + } +} From a286b15d103c1440f38fe6f20db0a6f69fcd6082 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Wed, 26 Apr 2023 17:32:33 -0600 Subject: [PATCH 2/9] added exclusion logic to smartdevice.py --- kasa/smartbulb.py | 6 +++--- kasa/smartdevice.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/kasa/smartbulb.py b/kasa/smartbulb.py index 40a805147..b28edab1b 100644 --- a/kasa/smartbulb.py +++ b/kasa/smartbulb.py @@ -204,11 +204,11 @@ def __init__(self, host: str) -> None: self._device_type = DeviceType.Bulb self.add_module("schedule", Schedule(self, "smartlife.iot.common.schedule")) self.add_module("usage", Usage(self, "smartlife.iot.common.schedule")) - # self.add_module("antitheft", Antitheft(self, "smartlife.iot.common.anti_theft")) + self.add_module("antitheft", Antitheft(self, "smartlife.iot.common.anti_theft")) self.add_module("time", Time(self, "smartlife.iot.common.timesetting")) self.add_module("emeter", Emeter(self, self.emeter_type)) - # self.add_module("countdown", Countdown(self, "countdown")) - # self.add_module("cloud", Cloud(self, "smartlife.iot.common.cloud")) + self.add_module("countdown", Countdown(self, "countdown")) + self.add_module("cloud", Cloud(self, "smartlife.iot.common.cloud")) @property # type: ignore @requires_update diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index e817958f7..ee0cd2bd7 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -27,6 +27,10 @@ _LOGGER = logging.getLogger(__name__) +# Certain module queries will crash devices; this list skips those queries +MODULE_EXCLUSIONS = { + "KL125(US)": ["antitheft", "cloud", "countdown"] +} class DeviceType(Enum): """Device type enum.""" @@ -325,10 +329,16 @@ async def _modular_update(self, req: dict) -> None: ) self.add_module("emeter", Emeter(self, self.emeter_type)) - for module in self.modules.values(): + + for module_key in self.modules: + module = self.modules[module_key] if not module.is_supported: _LOGGER.debug("Module %s not supported, skipping" % module) continue + elif self.model in MODULE_EXCLUSIONS and ( module_key in MODULE_EXCLUSIONS[self.model] ): + _LOGGER.debug("Module %s is excluded for %s, skipping" % (module, self.model)) + continue + q = module.query() _LOGGER.debug("Adding query for %s: %s", module, q) req = merge(req, q) From 9a8cfcc6aae77ae860419a0ea54bb93bdb2f9ec9 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Wed, 26 Apr 2023 17:33:48 -0600 Subject: [PATCH 3/9] cleaning up a name --- kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json b/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json index 22b210fa9..94d916b54 100644 --- a/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json +++ b/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json @@ -20,7 +20,7 @@ "system": { "get_sysinfo": { "active_mode": "none", - "alias": "Nightstand: Lisa (kasa-bc04)", + "alias": "Nightstand (kasa-bc04)", "ctrl_protocols": { "name": "Linkie", "version": "1.0" From 9bee885749d811a1f847ae6eab3f74ccfef999b2 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Mon, 1 May 2023 20:20:33 -0600 Subject: [PATCH 4/9] removing test fixture that isn't related to this PR --- kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json | 88 ------------------- 1 file changed, 88 deletions(-) delete mode 100644 kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json diff --git a/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json b/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json deleted file mode 100644 index 94d916b54..000000000 --- a/kasa/tests/fixtures/KL125(US)_1.20_1.0.7.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "smartlife.iot.common.emeter": { - "get_realtime": { - "err_code": 0, - "power_mw": 10800, - "total_wh": 42 - } - }, - "smartlife.iot.smartbulb.lightingservice": { - "get_light_state": { - "brightness": 100, - "color_temp": 0, - "err_code": 0, - "hue": 0, - "mode": "normal", - "on_off": 1, - "saturation": 0 - } - }, - "system": { - "get_sysinfo": { - "active_mode": "none", - "alias": "Nightstand (kasa-bc04)", - "ctrl_protocols": { - "name": "Linkie", - "version": "1.0" - }, - "description": "Smart Wi-Fi LED Bulb with Color Changing", - "dev_state": "normal", - "deviceId": "0000000000000000000000000000000000000000", - "disco_ver": "1.0", - "err_code": 0, - "hwId": "00000000000000000000000000000000", - "hw_ver": "1.20", - "is_color": 1, - "is_dimmable": 1, - "is_factory": false, - "is_variable_color_temp": 1, - "latitude_i": 0, - "light_state": { - "brightness": 100, - "color_temp": 0, - "hue": 0, - "mode": "normal", - "on_off": 1, - "saturation": 0 - }, - "longitude_i": 0, - "mic_mac": "000000000000", - "mic_type": "IOT.SMARTBULB", - "model": "KL125(US)", - "oemId": "00000000000000000000000000000000", - "preferred_state": [ - { - "brightness": 41, - "color_temp": 2700, - "hue": 0, - "index": 0, - "saturation": 0 - }, - { - "brightness": 100, - "color_temp": 0, - "hue": 0, - "index": 1, - "saturation": 100 - }, - { - "brightness": 100, - "color_temp": 0, - "hue": 120, - "index": 2, - "saturation": 100 - }, - { - "brightness": 100, - "color_temp": 0, - "hue": 240, - "index": 3, - "saturation": 100 - } - ], - "rssi": -70, - "status": "new", - "sw_ver": "1.0.7 Build 211009 Rel.172044" - } - } -} From fe39462ac4574cf2c651d24604d7033a1770d1b6 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Mon, 1 May 2023 20:20:58 -0600 Subject: [PATCH 5/9] incorporating PR feedback --- kasa/smartdevice.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index ee0cd2bd7..d06101d91 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -28,7 +28,8 @@ _LOGGER = logging.getLogger(__name__) # Certain module queries will crash devices; this list skips those queries -MODULE_EXCLUSIONS = { +# https://github.com/python-kasa/python-kasa/issues/345 +MODEL_MODULE_SKIPLIST = { "KL125(US)": ["antitheft", "cloud", "countdown"] } @@ -330,12 +331,12 @@ async def _modular_update(self, req: dict) -> None: self.add_module("emeter", Emeter(self, self.emeter_type)) - for module_key in self.modules: - module = self.modules[module_key] + for module_name, module in self.modules.items(): if not module.is_supported: _LOGGER.debug("Module %s not supported, skipping" % module) continue - elif self.model in MODULE_EXCLUSIONS and ( module_key in MODULE_EXCLUSIONS[self.model] ): + modules_to_skip = MODEL_MODULE_SKIPLIST.get(self.model, []) + if self.model in modules_to_skip: _LOGGER.debug("Module %s is excluded for %s, skipping" % (module, self.model)) continue From f75468cc8c492317ab47b6d610641e83c64f0bdd Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Mon, 1 May 2023 20:46:24 -0600 Subject: [PATCH 6/9] fixed an if statement --- kasa/smartdevice.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index d06101d91..a5b1dbf92 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -330,13 +330,12 @@ async def _modular_update(self, req: dict) -> None: ) self.add_module("emeter", Emeter(self, self.emeter_type)) - for module_name, module in self.modules.items(): if not module.is_supported: _LOGGER.debug("Module %s not supported, skipping" % module) continue modules_to_skip = MODEL_MODULE_SKIPLIST.get(self.model, []) - if self.model in modules_to_skip: + if module_name in modules_to_skip: _LOGGER.debug("Module %s is excluded for %s, skipping" % (module, self.model)) continue From 36dd468219c9e811741553cf84a726a375d31d39 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Mon, 1 May 2023 21:18:49 -0600 Subject: [PATCH 7/9] reduced exclusion list to just 'cloud' --- kasa/smartdevice.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index a5b1dbf92..b829d8899 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -30,7 +30,8 @@ # Certain module queries will crash devices; this list skips those queries # https://github.com/python-kasa/python-kasa/issues/345 MODEL_MODULE_SKIPLIST = { - "KL125(US)": ["antitheft", "cloud", "countdown"] + # "KL125(US)": ["antitheft", "cloud", "countdown"] + # "KL125(US)": ["cloud"] } class DeviceType(Enum): From c882768a7f0aba643d8da13322189375b1ecc5e0 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Wed, 17 May 2023 17:28:02 -0600 Subject: [PATCH 8/9] Tidy up the issue comment Co-authored-by: Teemu R. --- kasa/smartdevice.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index b829d8899..8cdc0dec1 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -28,10 +28,8 @@ _LOGGER = logging.getLogger(__name__) # Certain module queries will crash devices; this list skips those queries -# https://github.com/python-kasa/python-kasa/issues/345 MODEL_MODULE_SKIPLIST = { - # "KL125(US)": ["antitheft", "cloud", "countdown"] - # "KL125(US)": ["cloud"] + "KL125(US)": ["cloud"] # Issue #345 } class DeviceType(Enum): From 6acd809330376fdfd20c943b0f8498ef207fcc21 Mon Sep 17 00:00:00 2001 From: Brian Davis Date: Thu, 18 May 2023 02:44:30 +0000 Subject: [PATCH 9/9] this seems to be what the linter whats --- kasa/smartdevice.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 8cdc0dec1..75efcded5 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -28,9 +28,8 @@ _LOGGER = logging.getLogger(__name__) # Certain module queries will crash devices; this list skips those queries -MODEL_MODULE_SKIPLIST = { - "KL125(US)": ["cloud"] # Issue #345 -} +MODEL_MODULE_SKIPLIST = {"KL125(US)": ["cloud"]} # Issue #345 + class DeviceType(Enum): """Device type enum.""" @@ -335,7 +334,7 @@ async def _modular_update(self, req: dict) -> None: continue modules_to_skip = MODEL_MODULE_SKIPLIST.get(self.model, []) if module_name in modules_to_skip: - _LOGGER.debug("Module %s is excluded for %s, skipping" % (module, self.model)) + _LOGGER.debug(f"Module {module} is excluded for {self.model}, skipping") continue q = module.query()