From 59c370b5cdcc1cbb4920a339f97055be8fcc5db7 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Tue, 1 Mar 2022 21:05:43 +0100 Subject: [PATCH] Don't crash on devices not reporting features Returns an empty set if no feature information is available --- kasa/smartdevice.py | 6 +++++- kasa/tests/test_smartdevice.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/kasa/smartdevice.py b/kasa/smartdevice.py index 25b916318..7a66a864d 100755 --- a/kasa/smartdevice.py +++ b/kasa/smartdevice.py @@ -262,7 +262,11 @@ async def _query_helper( @requires_update def features(self) -> Set[str]: """Return a set of features that the device supports.""" - return set(self.sys_info["feature"].split(":")) + try: + return set(self.sys_info["feature"].split(":")) + except KeyError: + _LOGGER.debug("Device does not have feature information") + return set() @property # type: ignore @requires_update diff --git a/kasa/tests/test_smartdevice.py b/kasa/tests/test_smartdevice.py index 2dfd96340..d977daeb3 100644 --- a/kasa/tests/test_smartdevice.py +++ b/kasa/tests/test_smartdevice.py @@ -139,3 +139,12 @@ async def test_childrens(dev): async def test_internal_state(dev): """Make sure the internal state returns the last update results.""" assert dev.internal_state == dev._last_update + + +async def test_features(dev): + """Make sure features is always accessible.""" + sysinfo = dev._last_update["system"]["get_sysinfo"] + if "feature" in sysinfo: + assert dev.features == set(sysinfo["feature"].split(":")) + else: + assert dev.features == set()