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:
Aric Forrest 2022-11-02 18:11:24 -07:00 committed by GitHub
parent ef98c2aed9
commit ec06331737
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -543,6 +543,20 @@ def _schedule_list(dev, 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)
@click.pass_context
async def presets(ctx):