Make device initialisation easier by reducing required imports (#936)

Adds username and password arguments to discovery to remove the need to import Credentials.
Creates TypeAliases in Device for connection configuration classes and DeviceType.
Using the API with these changes will only require importing either Discover or Device
depending on whether using Discover.discover() or Device.connect() to 
initialize and interact with the API.
This commit is contained in:
Steven B
2024-06-03 21:06:54 +03:00
committed by GitHub
parent bfba7a347f
commit be5202ccb7
12 changed files with 263 additions and 90 deletions

View File

@@ -18,13 +18,13 @@ from pydantic.v1 import ValidationError
from kasa import (
AuthenticationError,
ConnectionType,
Credentials,
Device,
DeviceConfig,
DeviceFamilyType,
DeviceConnectionParameters,
DeviceEncryptionType,
DeviceFamily,
Discover,
EncryptType,
Feature,
KasaException,
Module,
@@ -87,11 +87,9 @@ TYPE_TO_CLASS = {
"smart.bulb": SmartDevice,
}
ENCRYPT_TYPES = [encrypt_type.value for encrypt_type in EncryptType]
ENCRYPT_TYPES = [encrypt_type.value for encrypt_type in DeviceEncryptionType]
DEVICE_FAMILY_TYPES = [
device_family_type.value for device_family_type in DeviceFamilyType
]
DEVICE_FAMILY_TYPES = [device_family_type.value for device_family_type in DeviceFamily]
# Block list of commands which require no update
SKIP_UPDATE_COMMANDS = ["wifi", "raw-command", "command"]
@@ -374,9 +372,9 @@ async def cli(
if type is not None:
dev = TYPE_TO_CLASS[type](host)
elif device_family and encrypt_type:
ctype = ConnectionType(
DeviceFamilyType(device_family),
EncryptType(encrypt_type),
ctype = DeviceConnectionParameters(
DeviceFamily(device_family),
DeviceEncryptionType(encrypt_type),
login_version,
)
config = DeviceConfig(