|
21 | 21 | from kasa.json import dumps as json_dumps
|
22 | 22 | from kasa.json import loads as json_loads
|
23 | 23 | from kasa.klapprotocol import TPLinkKlap
|
24 |
| -from kasa.protocol import TPLinkSmartHomeProtocol |
| 24 | +from kasa.protocol import TPLinkProtocol, TPLinkSmartHomeProtocol |
25 | 25 | from kasa.smartdevice import SmartDevice, SmartDeviceException
|
26 | 26 | from kasa.smartplug import SmartPlug
|
27 | 27 | from kasa.tapo.tapoplug import TapoPlug
|
@@ -380,37 +380,38 @@ def _get_device_instance(
|
380 | 380 | f"Unable to read response from device: {ip}: {ex}"
|
381 | 381 | ) from ex
|
382 | 382 |
|
383 |
| - if discovery_result.mgt_encrypt_schm.encrypt_type in ("KLAP", "AES"): |
384 |
| - type_ = discovery_result.device_type |
385 |
| - device_class = None |
386 |
| - supported_device_types: dict[str, Type[SmartDevice]] = { |
387 |
| - "SMART.TAPOPLUG": TapoPlug, |
388 |
| - "SMART.KASAPLUG": TapoPlug, |
389 |
| - "IOT.SMARTPLUGSWITCH": SmartPlug, |
390 |
| - } |
391 |
| - |
392 |
| - if discovery_result.device_type in supported_device_types: |
393 |
| - device_class = supported_device_types[discovery_result.device_type] |
394 |
| - |
395 |
| - if device_class: |
396 |
| - _LOGGER.debug("[DISCOVERY] %s << %s", ip, info) |
397 |
| - device = device_class(ip, port=port, credentials=credentials) |
398 |
| - device.update_from_discover_info(discovery_result.get_dict()) |
399 |
| - if discovery_result.mgt_encrypt_schm.encrypt_type == "KLAP": |
400 |
| - device.protocol = TPLinkKlap(ip, credentials=credentials) |
401 |
| - else: |
402 |
| - device.protocol = TPLinkAes( |
403 |
| - ip, |
404 |
| - credentials=credentials, |
405 |
| - login_version=discovery_result.mgt_encrypt_schm.lv, |
406 |
| - ) |
407 |
| - return device |
408 |
| - else: |
409 |
| - raise UnsupportedDeviceException( |
410 |
| - f"Unsupported device {ip} of type {type_}: {info}" |
411 |
| - ) |
412 |
| - else: |
413 |
| - raise UnsupportedDeviceException(f"Unsupported device {ip}: {info}") |
| 383 | + type_ = discovery_result.device_type |
| 384 | + encrypt_type_ = ( |
| 385 | + f"{type_.split('.')[0]}.{discovery_result.mgt_encrypt_schm.encrypt_type}" |
| 386 | + ) |
| 387 | + device_class = None |
| 388 | + |
| 389 | + supported_device_types: dict[str, Type[SmartDevice]] = { |
| 390 | + "SMART.TAPOPLUG": TapoPlug, |
| 391 | + "SMART.KASAPLUG": TapoPlug, |
| 392 | + "IOT.SMARTPLUGSWITCH": SmartPlug, |
| 393 | + } |
| 394 | + supported_device_protocols: dict[str, Type[TPLinkProtocol]] = { |
| 395 | + "IOT.KLAP": TPLinkKlap, |
| 396 | + "SMART.AES": TPLinkAes, |
| 397 | + } |
| 398 | + |
| 399 | + if (device_class := supported_device_types.get(type_)) is None: |
| 400 | + _LOGGER.warning("Got unsupported device type: %s", type_) |
| 401 | + raise UnsupportedDeviceException( |
| 402 | + f"Unsupported device {ip} of type {type_}: {info}" |
| 403 | + ) |
| 404 | + if (protocol_class := supported_device_protocols.get(encrypt_type_)) is None: |
| 405 | + _LOGGER.warning("Got unsupported device type: %s", encrypt_type_) |
| 406 | + raise UnsupportedDeviceException( |
| 407 | + f"Unsupported encryption scheme {ip} of type {encrypt_type_}: {info}" |
| 408 | + ) |
| 409 | + |
| 410 | + _LOGGER.debug("[DISCOVERY] %s << %s", ip, info) |
| 411 | + device = device_class(ip, port=port, credentials=credentials) |
| 412 | + device.protocol = protocol_class(ip, credentials=credentials) |
| 413 | + device.update_from_discover_info(discovery_result.get_dict()) |
| 414 | + return device |
414 | 415 |
|
415 | 416 |
|
416 | 417 | class DiscoveryResult(BaseModel):
|
|
0 commit comments