mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-10 14:57:07 +00:00
Drop deprecated, type-specific options in favor of --type (#336)
* Drop deprecated, type-specific options in favor of --type * Fix tests
This commit is contained in:
parent
6e988bd9a9
commit
631762b50c
25
kasa/cli.py
25
kasa/cli.py
@ -53,10 +53,6 @@ pass_dev = click.make_pass_decorator(SmartDevice)
|
|||||||
help="The broadcast address to be used for discovery.",
|
help="The broadcast address to be used for discovery.",
|
||||||
)
|
)
|
||||||
@click.option("-d", "--debug", envvar="KASA_DEBUG", default=False, is_flag=True)
|
@click.option("-d", "--debug", envvar="KASA_DEBUG", default=False, is_flag=True)
|
||||||
@click.option("--bulb", default=False, is_flag=True)
|
|
||||||
@click.option("--plug", default=False, is_flag=True)
|
|
||||||
@click.option("--lightstrip", default=False, is_flag=True)
|
|
||||||
@click.option("--strip", default=False, is_flag=True)
|
|
||||||
@click.option(
|
@click.option(
|
||||||
"--type",
|
"--type",
|
||||||
envvar="KASA_TYPE",
|
envvar="KASA_TYPE",
|
||||||
@ -65,7 +61,7 @@ pass_dev = click.make_pass_decorator(SmartDevice)
|
|||||||
)
|
)
|
||||||
@click.version_option(package_name="python-kasa")
|
@click.version_option(package_name="python-kasa")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
async def cli(ctx, host, alias, target, debug, bulb, plug, lightstrip, strip, type):
|
async def cli(ctx, host, alias, target, debug, type):
|
||||||
"""A tool for controlling TP-Link smart home devices.""" # noqa
|
"""A tool for controlling TP-Link smart home devices.""" # noqa
|
||||||
# no need to perform any checks if we are just displaying the help
|
# no need to perform any checks if we are just displaying the help
|
||||||
if sys.argv[-1] == "--help":
|
if sys.argv[-1] == "--help":
|
||||||
@ -95,19 +91,6 @@ async def cli(ctx, host, alias, target, debug, bulb, plug, lightstrip, strip, ty
|
|||||||
await ctx.invoke(discover)
|
await ctx.invoke(discover)
|
||||||
return
|
return
|
||||||
|
|
||||||
if bulb or plug or strip or lightstrip:
|
|
||||||
click.echo(
|
|
||||||
"Using --bulb, --plug, --strip, and --lightstrip is deprecated. Use --type instead to define the type"
|
|
||||||
)
|
|
||||||
if bulb:
|
|
||||||
type = "bulb"
|
|
||||||
elif plug:
|
|
||||||
type = "plug"
|
|
||||||
elif strip:
|
|
||||||
type = "strip"
|
|
||||||
elif lightstrip:
|
|
||||||
type = "lightstrip"
|
|
||||||
|
|
||||||
if type is not None:
|
if type is not None:
|
||||||
dev = TYPE_TO_CLASS[type](host)
|
dev = TYPE_TO_CLASS[type](host)
|
||||||
else:
|
else:
|
||||||
@ -158,9 +141,8 @@ async def join(dev: SmartDevice, ssid, password, keytype):
|
|||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("--timeout", default=3, required=False)
|
@click.option("--timeout", default=3, required=False)
|
||||||
@click.option("--dump-raw", is_flag=True)
|
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
async def discover(ctx, timeout, dump_raw):
|
async def discover(ctx, timeout):
|
||||||
"""Discover devices in the network."""
|
"""Discover devices in the network."""
|
||||||
target = ctx.parent.params["target"]
|
target = ctx.parent.params["target"]
|
||||||
click.echo(f"Discovering devices on {target} for {timeout} seconds")
|
click.echo(f"Discovering devices on {target} for {timeout} seconds")
|
||||||
@ -201,8 +183,7 @@ async def sysinfo(dev):
|
|||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@pass_dev
|
@pass_dev
|
||||||
@click.pass_context
|
async def state(dev: SmartDevice):
|
||||||
async def state(ctx, dev: SmartDevice):
|
|
||||||
"""Print out device state and versions."""
|
"""Print out device state and versions."""
|
||||||
click.echo(click.style(f"== {dev.alias} - {dev.model} ==", bold=True))
|
click.echo(click.style(f"== {dev.alias} - {dev.model} ==", bold=True))
|
||||||
click.echo(f"\tHost: {dev.host}")
|
click.echo(f"\tHost: {dev.host}")
|
||||||
|
@ -106,22 +106,6 @@ async def test_brightness(dev):
|
|||||||
assert "Brightness: 12" in res.output
|
assert "Brightness: 12" in res.output
|
||||||
|
|
||||||
|
|
||||||
def _generate_type_class_pairs():
|
|
||||||
yield from TYPE_TO_CLASS.items()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("type_class", _generate_type_class_pairs())
|
|
||||||
async def test_deprecated_type(dev, type_class, mocker):
|
|
||||||
"""Make sure that using deprecated types yields a warning."""
|
|
||||||
type, cls = type_class
|
|
||||||
if type == "dimmer":
|
|
||||||
return
|
|
||||||
runner = CliRunner()
|
|
||||||
with mocker.patch("kasa.SmartDevice.update"):
|
|
||||||
res = await runner.invoke(cli, ["--host", "127.0.0.2", f"--{type}"])
|
|
||||||
assert "Using --bulb, --plug, --strip, and --lightstrip is deprecated" in res.output
|
|
||||||
|
|
||||||
|
|
||||||
async def test_temperature(dev):
|
async def test_temperature(dev):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user