Add UnsupportedEncryptionError for unsupported encryption schemes (#1866)
Some checks failed
CI / Perform Lint Checks (3.15) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.14 on macos-latest (push) Has been cancelled
CI / Python 3.15 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.14 on ubuntu-latest (push) Has been cancelled
CI / Python 3.15 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CI / Python 3.14 on windows-latest (push) Has been cancelled
CI / Python 3.15 on windows-latest (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled

This commit is contained in:
Teemu R.
2026-11-28 01:13:53 +01:00
committed by GitHub
parent 422194e5eb
commit 6a35bb6e53
8 changed files with 53 additions and 13 deletions

View File

@@ -34,6 +34,7 @@ from kasa.exceptions import (
KasaException,
TimeoutError,
UnsupportedDeviceError,
UnsupportedEncryptionError,
)
from kasa.feature import Feature
from kasa.interfaces.light import HSV, ColorTempRange, Light, LightState
@@ -71,6 +72,7 @@ __all__ = [
"DeviceError",
"DeviceUnavailableError",
"UnsupportedDeviceError",
"UnsupportedEncryptionError",
"TimeoutError",
"Credentials",
"DeviceConfig",

View File

@@ -14,6 +14,7 @@ from kasa import (
Device,
Discover,
UnsupportedDeviceError,
UnsupportedEncryptionError,
)
from kasa.discover import (
NEW_DISCOVERY_REDACTORS,
@@ -170,7 +171,11 @@ async def list(ctx: click.Context) -> DeviceDict:
async def print_unsupported(unsupported_exception: UnsupportedDeviceError):
if host := unsupported_exception.host:
echo(f"{host:<15} UNSUPPORTED DEVICE")
if isinstance(unsupported_exception, UnsupportedEncryptionError):
reason = f"ENCRYPTION {unsupported_exception.encryption_type}"
echo(f"{host:<15} UNSUPPORTED {reason}")
else:
echo(f"{host:<15} UNSUPPORTED DEVICE")
echo(
f"{'HOST':<15} {'MODEL':<9} {'DEVICE FAMILY':<20} {'ENCRYPT':<7} "

View File

@@ -124,6 +124,7 @@ from kasa.exceptions import (
KasaException,
TimeoutError,
UnsupportedDeviceError,
UnsupportedEncryptionError,
)
from kasa.iot.iotdevice import IotDevice, _extract_sys_info
from kasa.json import DataClassJSONMixin
@@ -847,11 +848,13 @@ class Discover:
)
if encrypt_type not in {e.value for e in DeviceEncryptionType}:
raise UnsupportedDeviceError(
raise UnsupportedEncryptionError(
f"Device {discovery_result.ip} ({type_}) uses unsupported "
f"encryption type {encrypt_type}",
f"encryption type {encrypt_type}, enabling third-party "
"compatibility in the official app may help",
discovery_result=discovery_result.to_dict(),
host=discovery_result.ip,
encryption_type=encrypt_type,
)
return DeviceConnectionParameters.from_values(
type_,

View File

@@ -35,6 +35,18 @@ class UnsupportedDeviceError(KasaException):
super().__init__(*args)
class UnsupportedEncryptionError(UnsupportedDeviceError):
"""Exception for devices using an encryption scheme not implemented here.
The device type may still be supported on firmware using another scheme.
``encryption_type`` is the raw scheme name the device reported, e.g. ``TPAP``.
"""
def __init__(self, *args: Any, **kwargs: Any) -> None:
self.encryption_type: str = kwargs["encryption_type"]
super().__init__(*args, **kwargs)
class DeviceError(KasaException):
"""Base exception for device errors."""