mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
Don't crash on devices not reporting features (#317)
Returns an empty set if no feature information is available
This commit is contained in:
parent
e3d76bea75
commit
b22f6b4eef
@ -262,7 +262,11 @@ class SmartDevice:
|
||||
@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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user