mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-23 03:33:35 +00:00
Adding cli command to delete a schedule rule (#391)
* adding cli option to delete rule * resolving black linting issue * simplifying command name Co-authored-by: Teemu R. <tpr@iki.fi> * updating rule filter Co-authored-by: Teemu R. <tpr@iki.fi>
This commit is contained in:
parent
ef98c2aed9
commit
ec06331737
14
kasa/cli.py
14
kasa/cli.py
@ -543,6 +543,20 @@ def _schedule_list(dev, type):
|
|||||||
click.echo(f"No rules of type {type}")
|
click.echo(f"No rules of type {type}")
|
||||||
|
|
||||||
|
|
||||||
|
@schedule.command(name="delete")
|
||||||
|
@pass_dev
|
||||||
|
@click.option("--id", type=str, required=True)
|
||||||
|
async def delete_rule(dev, id):
|
||||||
|
"""Delete rule from device."""
|
||||||
|
schedule = dev.modules["schedule"]
|
||||||
|
rule_to_delete = next(filter(lambda rule: (rule.id == id), schedule.rules), None)
|
||||||
|
if rule_to_delete:
|
||||||
|
click.echo(f"Deleting rule id {id}")
|
||||||
|
await schedule.delete_rule(rule_to_delete)
|
||||||
|
else:
|
||||||
|
click.echo(f"No rule with id {id} was found")
|
||||||
|
|
||||||
|
|
||||||
@cli.group(invoke_without_command=True)
|
@cli.group(invoke_without_command=True)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
async def presets(ctx):
|
async def presets(ctx):
|
||||||
|
Loading…
Reference in New Issue
Block a user