mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-14 16:44:15 +00:00
Raise UnsupportedDeviceError instead of crashing on unknown device types (#1781)
Use get() instead of index accessor to avoid crashing on unknown devices. --------- Co-authored-by: GhostCoder6969 <ghostcoder6969@gmail.com>
This commit is contained in:
@@ -21,6 +21,7 @@ from kasa import (
|
||||
KasaException,
|
||||
SmartCamProtocol,
|
||||
SmartProtocol,
|
||||
UnsupportedDeviceError,
|
||||
)
|
||||
from kasa.device_factory import (
|
||||
Device,
|
||||
@@ -31,6 +32,7 @@ from kasa.device_factory import (
|
||||
SmartDevice,
|
||||
connect,
|
||||
get_device_class_from_family,
|
||||
get_device_class_from_sys_info,
|
||||
get_protocol,
|
||||
)
|
||||
from kasa.deviceconfig import (
|
||||
@@ -212,6 +214,26 @@ async def test_device_types(dev: Device) -> None:
|
||||
assert dev.device_type == res
|
||||
|
||||
|
||||
def test_device_class_from_unsupported_legacy_camera() -> None:
|
||||
"""IOT.IPCAMERA sysinfo raises UnsupportedDeviceError instead of KeyError."""
|
||||
info = {
|
||||
"system": {
|
||||
"get_sysinfo": {
|
||||
"system": {
|
||||
"type": "IOT.IPCAMERA",
|
||||
"model": "EC60(US)",
|
||||
"alias": "Kasa Cam",
|
||||
"dev_name": "Kasa Spot",
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
with pytest.raises(UnsupportedDeviceError, match="Unsupported device type"):
|
||||
get_device_class_from_sys_info(info)
|
||||
with pytest.raises(UnsupportedDeviceError, match="Unsupported device type"):
|
||||
Discover._get_device_class(info)
|
||||
|
||||
|
||||
@pytest.mark.xdist_group(name="caplog")
|
||||
async def test_device_class_from_unknown_family(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
|
||||
Reference in New Issue
Block a user