From 29c91151e3949459b3d0adc1b9b7d8bb379e40a4 Mon Sep 17 00:00:00 2001 From: Annika Jacobs <7255210+annikajayuk@users.noreply.github.com> Date: Fri, 23 Nov 2018 21:39:58 +0000 Subject: [PATCH] cli: show an error for incorrect hsv values (#142) * cli: fix hsv get Raising an exception if an incomplete HSV colour is provided. * cli hsv: clarify error message * cli hsv: clarify error message (again) --- pyHS100/cli.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pyHS100/cli.py b/pyHS100/cli.py index 50c9a5d7..75d737ba 100644 --- a/pyHS100/cli.py +++ b/pyHS100/cli.py @@ -209,14 +209,17 @@ def temperature(dev, temperature): @cli.command() -@click.argument("h", type=click.IntRange(0, 360), default=None) -@click.argument("s", type=click.IntRange(0, 100), default=None) -@click.argument("v", type=click.IntRange(0, 100), default=None) +@click.argument("h", type=click.IntRange(0, 360), default=None, required=False) +@click.argument("s", type=click.IntRange(0, 100), default=None, required=False) +@click.argument("v", type=click.IntRange(0, 100), default=None, required=False) +@click.pass_context @pass_dev -def hsv(dev, h, s, v): +def hsv(dev, ctx, h, s, v): """Get or set color in HSV. (Bulb only)""" - if h is None or s is None or v is None: - click.echo("Current HSV: %s" % dev.hsv) + if h is None: + click.echo("Current HSV: %s %s %s" % dev.hsv) + elif s is None or v is None: + raise click.BadArgumentUsage("Setting a color requires 3 values.", ctx) else: click.echo("Setting HSV: %s %s %s" % (h, s, v)) dev.hsv = (h, s, v)