-
-
Notifications
You must be signed in to change notification settings - Fork 43
Simplify the V1 methods by using single re-usable base methods #125
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: master
Are you sure you want to change the base?
Conversation
|
Thanks for adding mix support! However, I have a concern about the API design: Passing inverter_type as a parameter to every method call creates unnecessary coupling and repetition. As I wrote in previous feedback (even though AI helped me phrase it): Inverter type is a property of the inverter, not a parameter of each operation. It should be determined once and reused internally, not passed around repeatedly. Here is how you could do it: |
@johanzander thanks for your comments, but there is no need to pass the type at all did you see |
examples/min_example_dashboard.py
Outdated
| raise Exception("No MIN_TLX device found to get energy data from.") | ||
|
|
||
| # energy data does not contain epvToday for some reason, so we need to calculate it | ||
| epv_today = energy_data["epv1Today"] + energy_data["epv2Today"] |
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.
great to add this to the library. But I have up to 4 individual PVs, so please use something more dynamic, taking into account the sum of up to 4 if present.
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.
@johanzander are they all of the same type or do you have a mix? that might be a interesting scenario
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.
added a sum
|
but you have modified min_example.py to take device type parameter. is this a mistake? |
examples/min_example.py
Outdated
| inverter_data = api.min_detail(inverter_sn) | ||
| inverter_data = api.device_details( | ||
| device_sn=inverter_sn, | ||
| device_type=device_type |
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.
passing device_type?
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.
let me check , but I believe I have 3 different ways to call the same methods , device_details() is the base method with sn and device type https://github.com/indykoning/PyPi_GrowattServer/pull/125/files#diff-12865f9986e5f28194397aae0efed2b7abc9137d18c0a09197682e6c7e65cd01R484-R511, the details() https://github.com/indykoning/PyPi_GrowattServer/pull/125/files#diff-12865f9986e5f28194397aae0efed2b7abc9137d18c0a09197682e6c7e65cd01R1225-R1227 where the sn and device type are set on the object, so not needed as params , I will roll back my changes in examples/min_example.py to use a backwards compatible min_detail(sn) which will just call device_details(sn, device_type=7 )
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.
Amazing!
Maybe name it v1_example.py instead of mix_v1_example.py since its a generic example?
revert changes in min_* example and add backwards compatible wrapper …
johanzander
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.
Backward compatibility with MIN inverters using V1 seem to work...
Will test the new harmonized V1 APIs later...
growattServer/open_api_v1.py
Outdated
| if DEBUG >= 1: | ||
| print(f"Saving {self.slugify(operation_name)}_data.json") # noqa: T201 | ||
| with open(f"{self.slugify(operation_name)}_data.json", "w") as f: # noqa: PTH123 | ||
| json.dump(response, f, indent=4, sort_keys=True) |
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.
Please remove debug code from prod version.
Im testing the library and I see these:
Saving getting_MIN_TLX_details_data.json
Saving getting_MIN_TLX_settings_data.json
Saving getting_MIN_TLX_energy_data_data.json
growattServer/open_api_v1.py
Outdated
| """Enumeration of Growatt device types.""" | ||
|
|
||
| MIX_SPH = 5 # MIX/SPH devices | ||
| MIN_TLX = 7 # MIN/TLX devices |
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.
For consistency, should you call the enum
MiX_SPH for SPH_MIX instead (<DEVICE_TYPE>)
consider adding all types in the enum:
INVERTER = 1
STORAGE = 2
OTHER = 3
MAX = 4
SPH_MIX = 5
SPA = 6
MIN_TLX = 7
PCS = 8
HPS = 9
PBD = 10
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.
The only thing consistent with their naming convention, is the inconsistency
Fix max to 4 for sum
|
Added Read commands |
Write values
|
@indykoning what it the process to get a review here? |
Add additional params
Write values
Fix code quality
|
Is this ever going to get anywhere? |
Summary
Checklist