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

Be more lax on unknown SMART devices by rytilahti · Pull Request #863 · 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 @@ -171,7 +171,13 @@ def get_device_class_from_family(device_type: str) -> type[Device] | None:
"IOT.SMARTPLUGSWITCH": IotPlug,
"IOT.SMARTBULB": IotBulb,
}
return supported_device_types.get(device_type)
if (
cls := supported_device_types.get(device_type)
) is None and device_type.startswith("SMART."):
_LOGGER.warning("Unknown SMART device with %s, using SmartDevice", device_type)
cls = SmartDevice

return cls


def get_protocol(
Expand Down
9 changes: 9 additions & 0 deletions kasa/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 @@ -13,6 +13,7 @@
from kasa.device_factory import (
_get_device_type_from_sys_info,
connect,
get_device_class_from_family,
get_protocol,
)
from kasa.deviceconfig import (
Expand Down Expand Up @@ -164,3 +165,11 @@ async def test_device_types(dev: Device):
res = _get_device_type_from_sys_info(dev._last_update)

assert dev.device_type == res


async def test_device_class_from_unknown_family(caplog):
"""Verify that unknown SMART devices yield a warning and fallback to SmartDevice."""
dummy_name = "SMART.foo"
with caplog.at_level(logging.WARNING):
assert get_device_class_from_family(dummy_name) == SmartDevice
assert f"Unknown SMART device with {dummy_name}" in caplog.text

Back | FazBrowse Home | New Git URL