From 927fe648ac60a354f5f9606defe687c6593917d2 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Mon, 10 Jun 2024 14:13:46 +0100 Subject: [PATCH] Better checking of child modules not supported by parent device (#966) Replaces the logic to skip adding child modules to parent devices based on whether a device is a wall switch and instead relies on the `_check_supported` method. Is more future proof and will fix issue with the P300 with child `auto_off` modules https://github.com/python-kasa/python-kasa/pull/915 not supported on the parent. --- kasa/smart/modules/lightpreset.py | 10 ++++++++++ kasa/smart/smartdevice.py | 4 ---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kasa/smart/modules/lightpreset.py b/kasa/smart/modules/lightpreset.py index e0a775af..0fb57952 100644 --- a/kasa/smart/modules/lightpreset.py +++ b/kasa/smart/modules/lightpreset.py @@ -140,3 +140,13 @@ class LightPreset(SmartModule, LightPresetInterface): if self._state_in_sysinfo: # Child lights can have states in the child info return {} return {self.QUERY_GETTER_NAME: None} + + async def _check_supported(self): + """Additional check to see if the module is supported by the device. + + Parent devices that report components of children such as ks240 will not have + the brightness value is sysinfo. + """ + # Look in _device.sys_info here because self.data is either sys_info or + # get_preset_rules depending on whether it's a child device or not. + return "brightness" in self._device.sys_info diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 9013fc93..6f02fad0 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -202,10 +202,6 @@ class SmartDevice(Device): child_modules_to_skip = {} if self._parent and self._parent.device_type != DeviceType.Hub: skip_parent_only_modules = True - elif self._children and self.device_type == DeviceType.WallSwitch: - # _initialize_modules is called on the parent after the children - for child in self._children.values(): - child_modules_to_skip.update(**child.modules) for mod in SmartModule.REGISTERED_MODULES.values(): _LOGGER.debug("%s requires %s", mod, mod.REQUIRED_COMPONENT)