Skip to content

cli.py usage year and month options do not output data as expected #373

@jules43

Description

@jules43

The kasa.exe (cli.py) usage option is intended to output a comma separated list of day,minutes or month,minutes instead it outputs the raw list/dict data.

A way to fix this is with the following code in the usage function (note I added a sort that may be redundant):

    if year:
        click.echo(f"== For year {year.year} ==")
        click.echo("Month, usage (minutes)")
        usage_data = await usage.get_monthstat(year=year.year)
        
        period="month"
        
    elif month:
        click.echo(f"== For month {month.month} of {month.year} ==")
        click.echo("Day, usage (minutes)")
        usage_data = await usage.get_daystat(year=month.year, month=month.month)

       period="day"

    else:
        # Call with no argument outputs summary data and returns
        click.echo("Today: %s minutes" % usage.usage_today)
        click.echo("This month: %s minutes" % usage.usage_this_month)

        return
        
    # output any detailed usage data
    usage_data = usage_data.get(period + "_list")
    usage_data.sort(key = lambda item: item.get(period))
    for usage in usage_data:
        click.echo(f'{usage.get(period)}, {usage.get("time")}')

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions