mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-15 06:38:42 +00:00
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:
18
kasa/cli.py
18
kasa/cli.py
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user