FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Raise UnsupportedDeviceError instead of crashing on unknown device types by GhostCoder6969 · Pull Request #1781 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 7 additions & 1 deletion kasa/device_factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ def get_device_class_from_sys_info(sysinfo: dict[str, Any]) -> type[IotDevice]:
# Disabled until properly implemented
# DeviceType.Camera: IotCamera,
}
return TYPE_TO_CLASS[IotDevice._get_device_type_from_sys_info(sysinfo)]
device_type = IotDevice._get_device_type_from_sys_info(sysinfo)
if (cls := TYPE_TO_CLASS.get(device_type)) is None:
raise UnsupportedDeviceError(
f"Unsupported device type: {device_type}",
discovery_result=sysinfo,
)
return cls


def get_device_class_from_family(
Expand Down
22 changes: 22 additions & 0 deletions tests/test_device_factory.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
KasaException,
SmartCamProtocol,
SmartProtocol,
UnsupportedDeviceError,
)
from kasa.device_factory import (
Device,
Expand All @@ -31,6 +32,7 @@
SmartDevice,
connect,
get_device_class_from_family,
get_device_class_from_sys_info,
get_protocol,
)
from kasa.deviceconfig import (
Expand Down Expand Up @@ -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,
Expand Down
Loading

Back | FazBrowse Home | New Git URL