-
Notifications
You must be signed in to change notification settings - Fork 33
Refactor TEDAPI __init__ for readability/code reuse #153
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
base: main
Are you sure you want to change the base?
Conversation
Thanks @mccahan ! Yes, I agree, it is a lot but I don't hate it. 😄 I pulled it down and the basic functions work, but pulling vitals throws errors: File "/pypowerwall/tedapi/vitals_dictionary.py", line 221, in __get_pvs_and_pvac_strings I didn't unwind the new vitals code so could be something simple. Some things I consider for refactors like this:
|
Theoretically, I may have fixed that issue in 5a7ce77 - apparently I don't have whatever kind of hardware that is? I tested this by opening
|
This reverts commit 1baa052.
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.
Overall: I like the direction this is going.
Functionality wise, my biggest concern is the change in how the api lock works. That is a big shift and I'm not yet convinced we want that.
Otherwise: I encourage you to break this pull request up into smaller increments. You need not move every single function over to your more modularized version at once. Do one at a time. That makes it easier to review and makes the blast radius from any bugs much smaller.
You're not wrong this should've been two PRs - I did pull the vitals part out into a separate branch just now (https://github.com/jasonacox/pypowerwall/compare/main...mccahan:chore/refactor-tedapi-vitals?expand=1) though I'm not sure I want to complicate a merge on this branch by removing/rebasing later. I did the side-by-side compare of The biggest risks (actual changes) are:
|
Re: Pain of rebasing. In the case of these gigantic refactors, the fact that you're scared to do it is a signal it's too big. In those cases I often don't rebase, but re-create from whole cloth using the old branch as a reference, that's often easier. |
Nah it's not fear of a rebase, it's that the fun part is over and the ADHD will kick in and I'll lose interest if I'm playing rebase tag lol. We could PR in https://github.com/jasonacox/pypowerwall/compare/main...mccahan:chore/refactor-tedapi-vitals?expand=1 as the smallest digestible chunk, and deal with that merge conflict if that merges first, but otherwise I'll probably decline trying to split this up function-by-function into a bunch of separate PRs. That feels like extra testing to me, dragging out a mystery piecemeal. |
@mccahan, this is really up to @jasonacox at this point :) |
Sorry for the delay. Besides some personal emergencies, this is a lot to review. While I also like the work/direction, I have some concerns.
I would appreciate thoughts and perspectives. I'm still going through the code but I do have a lot going on now. Thanks for your patience. |
@mccahan Based on @jasonacox's comments: If your ADHD really does prevent you from splitting this up and staying the course, I'm happy to do it. I do this kind of thing all the time at my job, and I'm eventually going to have to do it with my refactor of the proxy. But this is your change not mine, and I won't without your blessing. |
Zero rush at all, hope things work out okay. I swapped the camel casing (habit, didn't even notice), but otherwise if this is too much I'm happy to just abandon this PR. It's essentially all copying/pasting around, so beyond theoretical maintainability there's no gain. I'd personally err on the side of bundling it rather than stringing it across a few versions so it's easier to pinpoint when something happened if there's a bug report. My test scenario has been running it side-by-side with the current production version and checking the results for each function; the substance parts of it would fail on requests because of changes to the caching, or the vitals wouldn't match up side-by-side (N.B. I have just the PW3 with none of the Neurio stuff). |
There is another way: Unit tests. Right now we have 0. We can cast the current behavior into unit tests, and if we have good enough coverage, refactor fearlessly :) |
@Nexarian be my guest! I pulled a chunk out of it into #159, but if you'd like to split this one up you're more than welcome to. I wouldn't split it too far so you don't end up sprawling it over six versions trying to trace down any issues, but whatever works there. I'm also not at all hurt if we ditch this entirely. (You just commented live lol) the only shortcoming to unit tests for this piece is that it wouldn't catch the primary risk of this particular PR, which is around testing it with hardware that I don't have. I think your hardware setup is more complicated, so maybe a few collections of responses from different systems to unit test vitals responses against could catch it, though that might become tedious quick if they start changing firmware responses. |
Alright, I'll work on this then. I think merging in the spirit of your changes before my crazy proxy refactor would do all of us a lot of good. |
This might be a bit much to bite off, so my feelings aren't hurt if we just skip it. I started just splitting the protobuf messages out to make the file more readable but then went on a yak-shaving expedition for a few things
Primary goal here is that the tedapi init file is massive and has a lot of copy/paste repeated code in it. To that end:
@uses_api_lock
decorator handle acquiring the locks@uses_cache(key)
and@uses_connection_required
decorators so each function call doesn't have to repeat that code__run_request
function to handle throttling, exceptions, etcvitals_dictionary.py
for readabilityFrom my testing everything seems to be working, but I only have a single PW3 so might be missing hardware to thoroughly test some pieces.
@Nexarian this is probably pertinent to your interests