diff --git a/kasa/tapo/childdevice.py b/kasa/tapo/childdevice.py index 7b66a79d3..58b1aa534 100644 --- a/kasa/tapo/childdevice.py +++ b/kasa/tapo/childdevice.py @@ -17,6 +17,7 @@ def __init__( self, parent: TapoDevice, child_id: str, + components: Dict, config: Optional[DeviceConfig] = None, protocol: Optional[SmartProtocol] = None, ) -> None: @@ -24,6 +25,7 @@ def __init__( self._parent = parent self._id = child_id self.protocol = _ChildProtocolWrapper(child_id, parent.protocol) + self._components = components async def update(self, update_children: bool = True): """We just set the info here accordingly.""" diff --git a/kasa/tapo/tapodevice.py b/kasa/tapo/tapodevice.py index a7e57a6d1..e204fb078 100644 --- a/kasa/tapo/tapodevice.py +++ b/kasa/tapo/tapodevice.py @@ -41,8 +41,27 @@ async def _initialize_children(self): # as hubs can also have them. from .childdevice import ChildDevice + async def _get_child_components(): + resp = await self.protocol.query("get_child_device_component_list") + components_raw = resp["get_child_device_component_list"][ + "child_component_list" + ] + return { + child["device_id"]: { + comp["id"]: comp["ver_code"] for comp in child["component_list"] + } + for child in components_raw + } + + components = await _get_child_components() + self.children = [ - ChildDevice(parent=self, child_id=child["device_id"]) for child in children + ChildDevice( + parent=self, + child_id=child["device_id"], + components=components[child["device_id"]], + ) + for child in children ] self._device_type = DeviceType.Strip @@ -58,6 +77,7 @@ async def update(self, update_children: bool = True): comp["id"]: comp["ver_code"] for comp in self._components_raw["component_list"] } + await self._initialize_modules() extra_reqs: Dict[str, Any] = {} diff --git a/kasa/tests/test_childdevice.py b/kasa/tests/test_childdevice.py index 986f77b65..8b0fb85c2 100644 --- a/kasa/tests/test_childdevice.py +++ b/kasa/tests/test_childdevice.py @@ -28,3 +28,15 @@ async def test_childdevice_update(dev, dummy_protocol, mocker): assert dev._last_update != first._last_update assert dev._last_update["child_info"]["child_device_list"][0] == first._last_update + + +@strip_smart +async def test_childdevice_components(dev, dummy_protocol, mocker): + """Test that childdevice components is correctly set.""" + first = dev.children[0] + assert first._components + # TODO: Fix tests, awaiting dev.update() fails + return + query_mock = mocker.patch.object(dev.protocol, "query") + await dev.update() + query_mock.assert_called_with("get_child_device_component_list")