mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-28 01:26:25 +00:00
tweak
This commit is contained in:
parent
f55428549f
commit
5fdec8ceb6
22
kasa/cli.py
22
kasa/cli.py
@ -10,14 +10,7 @@ from typing import Any, Dict, cast
|
|||||||
|
|
||||||
import asyncclick as click
|
import asyncclick as click
|
||||||
|
|
||||||
from kasa import (
|
from kasa import Credentials, DeviceType, Discover, SmartBulb, SmartDevice, SmartStrip
|
||||||
Credentials,
|
|
||||||
DeviceType,
|
|
||||||
Discover,
|
|
||||||
SmartBulb,
|
|
||||||
SmartDevice,
|
|
||||||
SmartStrip,
|
|
||||||
)
|
|
||||||
from kasa.device_factory import DEVICE_TYPE_TO_CLASS
|
from kasa.device_factory import DEVICE_TYPE_TO_CLASS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -41,11 +34,11 @@ except ImportError:
|
|||||||
# --json has set it to _nop_echo
|
# --json has set it to _nop_echo
|
||||||
echo = _do_echo
|
echo = _do_echo
|
||||||
|
|
||||||
TYPE_TO_CLASS = {
|
DEVICE_TYPES = [
|
||||||
device_type.value: DEVICE_TYPE_TO_CLASS[device_type]
|
device_type.value
|
||||||
for device_type in DeviceType
|
for device_type in DeviceType
|
||||||
if device_type in DEVICE_TYPE_TO_CLASS
|
if device_type in DEVICE_TYPE_TO_CLASS
|
||||||
}
|
]
|
||||||
|
|
||||||
click.anyio_backend = "asyncio"
|
click.anyio_backend = "asyncio"
|
||||||
|
|
||||||
@ -125,7 +118,7 @@ def json_formatter_cb(result, **kwargs):
|
|||||||
"--type",
|
"--type",
|
||||||
envvar="KASA_TYPE",
|
envvar="KASA_TYPE",
|
||||||
default=None,
|
default=None,
|
||||||
type=click.Choice(list(TYPE_TO_CLASS), case_sensitive=False),
|
type=click.Choice(DEVICE_TYPES, case_sensitive=False),
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--json", default=False, is_flag=True, help="Output raw device response as JSON."
|
"--json", default=False, is_flag=True, help="Output raw device response as JSON."
|
||||||
@ -231,7 +224,10 @@ async def cli(
|
|||||||
return await ctx.invoke(discover, timeout=discovery_timeout)
|
return await ctx.invoke(discover, timeout=discovery_timeout)
|
||||||
|
|
||||||
if type is not None:
|
if type is not None:
|
||||||
dev = TYPE_TO_CLASS[type](host, credentials=credentials)
|
device_type = DeviceType.from_value(type)
|
||||||
|
dev = SmartDevice.connect(
|
||||||
|
host, credentials=credentials, device_type=device_type
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
echo("No --type defined, discovering..")
|
echo("No --type defined, discovering..")
|
||||||
dev = await Discover.discover_single(
|
dev = await Discover.discover_single(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user