Skip to content

Conversation

@BuongiornoTexas
Copy link
Contributor

Fix crash when kasa cli is called with --month or --year arguments.

Per discussions in #102.

Fix crash when kasa cli is called with --month or --year arguments.
Copy link
Contributor

@kirichkov kirichkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Run 'black' before patching.
  2. I think the best solution is to move lines 338-344 to be below 331, and part of that else block.
  3. Move the check for isinstance (
    if isinstance(emeter_status, list):
    ) to be part of the ifs at
    if year:
    and at
    elif month:

kasa/cli.py Outdated
click.echo(f"== For year {year.year} ==")
emeter_status = await dev.get_emeter_monthly(year.year)
click.echo(await dev.get_emeter_monthly(year.year))
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These returns will return from the function so no data will be printed out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm echoing the returned values and then exiting. I'm just not using emeter_status as intermediate variable. Data is absolutely printed.

Agreed that we can eliminate the returns if we adopt your change 2 above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be no intermediate status saving, considering the output format for realtime is different for the historical ones. If it looks like that the historical data formats are similar, it makes sense to share some of that code, though.

@BuongiornoTexas
Copy link
Contributor Author

  1. Run 'black' before patching.

Done.

  1. I think the best solution is to move lines 338-344 to be below 331, and part of that else block.

This makes sense, and allows eliminations of the returns for the year and month blocks. I'll implement after we resolve the list instance issue.

  1. Move the check for isinstance (

I don't understand this. Both definitions of get_emeter_monthly and get_emeter_daily return dicts (smartdevice.py, smartstrip.py). So any test for list instances will always fail for these methods.

I don't know where the lists are supposed to come from, but it is absolutely not from the monthly/yearly methods as currently implemented. I'd assumed this was to capture smartstrip summary data.

@kirichkov
Copy link
Contributor

I don't know where the lists are supposed to come from, but it is absolutely not from the monthly/yearly methods as currently implemented. I'd assumed this was to capture smartstrip summary data.

Oooops! You are right! I'm sorry for the misdirection I gave you!

@rytilahti any idea why the CLI is still checking for emeter returning lists when no such thing is returned from any of the emeter functions?

@rytilahti
Copy link
Member

Sorry, I currently have very spotty internet connectivity. But the idea is correct, yearly and monthly responses should be handled separately to the realtime one (the information is different for the historical responses). I think the incorrect behavior is just a leftover from the port, I cannot really recall why I thought the historical data would be reported in the same format but in a list.

In my opinion the best way is to deal the historical data completely separately from the real time data. Please feel free to use a prettier output format than simply echoing out the response from the calls.

(please also update the PR title to be more informative, thanks!)

@BuongiornoTexas
Copy link
Contributor Author

OK - with the last round of comments, I think I can do a clean implementation. Update to follow in a day or so.

For the historical data, how about something like this (works well for as I can then translate to excel data sets trivially)?

== For year 2020 ==
    Month, Monthly usage (kWh) 
         4, 80.9
         5, 62.3
         6. 18.0

@kirichkov
Copy link
Contributor

CSV-like looks good to me. Makes it easier to parse too.

@BuongiornoTexas BuongiornoTexas changed the title Update cli.py Update cli.py to addresss crash on year/month calls and improve output formatting Sep 19, 2020
@BuongiornoTexas
Copy link
Contributor Author

OK - I think that will do it. I ended up doing plain CSV with no spacing to make copy/pasting data simpler.

@kirichkov
Copy link
Contributor

@rytilahti It looks good to me, let me know if I can merge or do so yourself if your Internet has improved :-)

@rytilahti
Copy link
Member

Hey, sorry for the delay! I just tested this with my hs110 and it looks fine to me, so let's get it merged. Thanks for the PR! 🎉

While I think the output format is fine as it is, if CSV output is really wanted it is far easier to less cumbersome to create a simple script to do that. The reason is that we are not giving any guarantees to the cli tool's output format while we have (I think so at least :-) an unwritten rule about not breaking the API for no reason.

@rytilahti rytilahti merged commit 70061cb into python-kasa:master Oct 3, 2020
@rytilahti rytilahti added the bug Something isn't working label Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants