Be more lax on unknown SMART devices (#863)

This commit is contained in:
Teemu R 2024-04-25 08:36:30 +02:00 committed by GitHub
parent 53b84b7683
commit 10629f2db9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -171,7 +171,13 @@ def get_device_class_from_family(device_type: str) -> type[Device] | None:
"IOT.SMARTPLUGSWITCH": IotPlug, "IOT.SMARTPLUGSWITCH": IotPlug,
"IOT.SMARTBULB": IotBulb, "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( def get_protocol(

View File

@ -13,6 +13,7 @@ from kasa import (
from kasa.device_factory import ( from kasa.device_factory import (
_get_device_type_from_sys_info, _get_device_type_from_sys_info,
connect, connect,
get_device_class_from_family,
get_protocol, get_protocol,
) )
from kasa.deviceconfig import ( from kasa.deviceconfig import (
@ -164,3 +165,11 @@ async def test_device_types(dev: Device):
res = _get_device_type_from_sys_info(dev._last_update) res = _get_device_type_from_sys_info(dev._last_update)
assert dev.device_type == res 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