Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions kasa/tapo/childdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def __init__(
self,
parent: TapoDevice,
child_id: str,
components: Dict,
config: Optional[DeviceConfig] = None,
protocol: Optional[SmartProtocol] = None,
) -> None:
super().__init__(parent.host, config=parent.config, protocol=parent.protocol)
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."""
Expand Down
22 changes: 21 additions & 1 deletion kasa/tapo/tapodevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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] = {}
Expand Down
12 changes: 12 additions & 0 deletions kasa/tests/test_childdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")