Add SPH device support via the regional mobile API#145
Conversation
3a70b9d to
4bed1df
Compare
Newer SPH inverters aren't reachable via the V1 OpenAPI. Add methods
that target the regional mobile host (server-{region}-api.growatt.com)
which is what the ShinePhone app uses.
Methods on GrowattApi:
- sph_system_status() — real-time values (SOC, PV, battery, grid, load)
- sph_energy_overview() — daily and lifetime totals
- sph_energy_prod_and_cons() — chart series (day/month/year/total)
- sph_settings() — full settings bean
- update_sph_inverter_setting() — write a setting
4bed1df to
df3d417
Compare
Add noqa comments for intentional datetime.now() without tz (local time is correct for the Growatt API) and for the chart_type magic number comparison (API constants documented in docstring). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
johanzander
left a comment
There was a problem hiding this comment.
Overall this looks good — clean, well-scoped, follows existing patterns (tlx_, mix_), and fills a real gap for newer SPH/SPM models that aren't reachable via V1 or the legacy mix/tlx/storage endpoints.
One thing I'd like the repo owner to weigh in on:
The change on line 90 of base_api.py switches __get_date_string from datetime.datetime.now(datetime.UTC) to naive datetime.datetime.now(). The reasoning in the comment is sound (Growatt interprets the date string in the plant's local timezone), but this is a behavioral change for all existing callers (e.g. plant_detail, mix_detail, tlx_energy_prod_cons), not just the new SPH methods. Users who were relying on the UTC default could see different results near midnight.
@indykoning — are you OK with this change to the shared __get_date_string default, or should we keep UTC there and only use local time in the new SPH-specific date handling?
|
One more thing: could you add type annotations to the new SPH methods? The rest of the codebase on master has them. |
I agree with this, though it could be a bug i introduced when adding and running ruff: If we could double check that e.g. the https://github.com/indykoning/PyPi_GrowattServer/blob/master/growattServer/base_api.py#L200 plant_detail function also uses the localized date instead of UTC my worries will have been taken care of. |
Summary
Newer SPH/SPM hybrid inverters (e.g. SPM-10000TL-HU) aren't reachable via the existing legacy mix_/tlx_/storage_* endpoints — those return null/zero values. They're also not reachable via the V1 sph_* methods because V1's device_list omits these devices entirely.
I proxied my phone and looks like ShinePhone mobile app to reverse engineer the same set of methods for SPH/SPM inverters:
An exampled is included:
examples/sph_legacy_example.pyChecklist