-
-
Notifications
You must be signed in to change notification settings - Fork 247
Update cli.py to addresss crash on year/month calls and improve output formatting #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix crash when kasa cli is called with --month or --year arguments.
kirichkov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Run 'black' before patching.
- I think the best solution is to move lines 338-344 to be below 331, and part of that else block.
- Move the check for isinstance () to be part of the
Line 333 in c59b748
if isinstance(emeter_status, list): ifs atand atLine 324 in c59b748
if year: Line 327 in c59b748
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Done.
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.
I don't understand this. Both definitions of 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? |
|
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!) |
|
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)? |
|
CSV-like looks good to me. Makes it easier to parse too. |
|
OK - I think that will do it. I ended up doing plain CSV with no spacing to make copy/pasting data simpler. |
|
@rytilahti It looks good to me, let me know if I can merge or do so yourself if your Internet has improved :-) |
|
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. |
Fix crash when kasa cli is called with --month or --year arguments.
Per discussions in #102.