From 88d3b5e32baf721895a8964819fecc9525d2606a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 19 Nov 2023 08:02:43 -0600 Subject: [PATCH] tweaks --- kasa/smartdevice.py | 6 ++++++ kasa/tests/test_smartdevice.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 4f850b5b..e7b7a38f 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -393,6 +393,12 @@ class SmartDevice: sys_info = self.sys_info return str(sys_info["alias"]) + @property # type: ignore + @requires_update + def has_children(self) -> bool: + """Check if the device has children devices.""" + return bool(self._sys_info.get("child_num")) + async def set_alias(self, alias: str) -> None: """Set the device name (alias).""" return await self._query_helper("system", "set_dev_alias", {"alias": alias}) diff --git a/kasa/tests/test_smartdevice.py b/kasa/tests/test_smartdevice.py index f0ece094..6e7cf80f 100644 --- a/kasa/tests/test_smartdevice.py +++ b/kasa/tests/test_smartdevice.py @@ -170,12 +170,14 @@ async def test_representation(dev): assert pattern.match(str(dev)) -async def test_childrens(dev): +async def test_children(dev): """Make sure that children property is exposed by every device.""" if dev.is_strip: assert len(dev.children) > 0 + assert dev.has_children is True else: assert len(dev.children) == 0 + assert dev.has_children is False async def test_internal_state(dev):