Skip to content

feat: add site-data API endpoints (PR 1)#126

Open
it-rec wants to merge 2 commits into
Solarlibs:mainfrom
it-rec:claude/se-api-site-data
Open

feat: add site-data API endpoints (PR 1)#126
it-rec wants to merge 2 commits into
Solarlibs:mainfrom
it-rec:claude/se-api-site-data

Conversation

@it-rec

@it-rec it-rec commented May 20, 2026

Copy link
Copy Markdown
Contributor

Adds the SolarEdge Monitoring API "Site Data" endpoints that were not yet wrapped by the client:

  • get_sites -> /sites/list
  • get_data_period -> /site/{id}/dataPeriod
  • get_data_period_bulk -> /sites/{ids}/dataPeriod
  • get_energy -> /site/{id}/energy
  • get_energy_bulk -> /sites/{ids}/energy
  • get_time_frame_energy[_bulk] -> /site|sites/.../timeFrameEnergy
  • get_power -> /site/{id}/power
  • get_power_bulk -> /sites/{ids}/power
  • get_overview_bulk -> /sites/{ids}/overview
  • get_power_details -> /site/{id}/powerDetails
  • get_environmental_benefits -> /site/{id}/envBenefits

Introduces shared infrastructure reused by later endpoint PRs: the Meter/TimeUnit/SystemUnits/SortOrder Literal aliases, the _format_date/_format_datetime/_join_ids helpers (so methods accept date, datetime or pre-formatted str), and the _get_sites_url builder for bulk calls.

One PR in a series splitting the full endpoint coverage work into reviewable pieces.

Adds the SolarEdge Monitoring API "Site Data" endpoints that were not
yet wrapped by the client:

- get_sites             -> /sites/list
- get_data_period       -> /site/{id}/dataPeriod
- get_data_period_bulk  -> /sites/{ids}/dataPeriod
- get_energy            -> /site/{id}/energy
- get_energy_bulk       -> /sites/{ids}/energy
- get_time_frame_energy[_bulk] -> /site|sites/.../timeFrameEnergy
- get_power             -> /site/{id}/power
- get_power_bulk        -> /sites/{ids}/power
- get_overview_bulk     -> /sites/{ids}/overview
- get_power_details     -> /site/{id}/powerDetails
- get_environmental_benefits -> /site/{id}/envBenefits

Introduces shared infrastructure reused by later endpoint PRs: the
Meter/TimeUnit/SystemUnits/SortOrder Literal aliases, the
_format_date/_format_datetime/_join_ids helpers (so methods accept
date, datetime or pre-formatted str), and the _get_sites_url builder
for bulk calls.

One PR in a series splitting the full endpoint coverage work into
reviewable pieces.
@it-rec it-rec changed the title feat: add site-data API endpoints feat: add site-data API endpoints (PR 1) May 20, 2026
@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@it-rec

it-rec commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

@bluetoothbot review

@bluetoothbot

Copy link
Copy Markdown

❌ Permission denied. Only users with write access can trigger bot commands.

@it-rec

it-rec commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@claude

@it-rec

it-rec commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@bdraco I also have this open since a while now.

As you said there is much on your plate. No worries.

My intend was to just draw your attention to this that it doesn't fall through the cracks either.

@bluetoothbot

Copy link
Copy Markdown

@it-rec: @bdraco I also have this open since a while now.

Reviewed. Source merges clean. One blocker: new tests use aioresponses. Main dropped it in #136. Now uses aiointercept. Rebase, then port tests to async with aiointercept(...). Recheck the query-param regexes after porting.

@bluetoothbot

Copy link
Copy Markdown

PR Review — feat: add site-data API endpoints (PR 1)

Solid, well-structured endpoint additions blocked by a test-framework mismatch with current main.

The source code is clean and merges cleanly: the shared _format_date/_format_datetime/_join_ids helpers and _get_sites_url builder are well-factored, the new code correctly uses an immutable () default for meters (avoiding the mutable-default trap the older get_energy_details still has), docstrings are thorough, and the date/datetime/str overloads are handled correctly (datetime is a subclass of date).

  • Blocking: the eight new tests use aioresponses, which main removed in test: switch from aioresponses to aiointercept #136 (migrated to aiointercept) — verified absent from pyproject.toml and poetry.lock. Tests won't collect after rebase.
  • The multi-param URL regexes rely on aioresponses' alphabetical param sorting; must be re-verified under aiointercept.
  • Minor: confirm SystemUnits literal ("Metrics" vs "Metric") against the SolarEdge spec; add a test for the metric case.

🔴 Blocking

1. New tests use aioresponses, which main has removed
tests/test_init.py:113-313

All eight added tests are written against aioresponses (with aioresponses() as mocked:), but main switched the test stack to aiointercept in commit #136 (9f0abd5). I verified aioresponses is gone from both pyproject.toml and poetry.lock, and tests/test_init.py on main now imports from aiointercept import aiointercept and uses async with aiointercept(mock_external_urls=True) as mocked:.

Why it matters: after rebasing onto current main, these tests fail at collection — aioresponses is neither imported nor installed (NameError / missing dependency). CI will not run them, so the new endpoints ship effectively untested.

How to fix:

  • Rebase the branch on current main.
  • Migrate each new test to the existing pattern: async with aiointercept(mock_external_urls=True) as mocked: (note: async context manager, not sync with).
  • Re-verify the regex URL matchers against aiointercept's query-string semantics (see separate note on param ordering).
with aioresponses() as mocked:  # main now uses: async with aiointercept(mock_external_urls=True) as mocked:

🟡 Important

1. Query-param regexes assume alphabetical param ordering
tests/test_init.py:121-126

The get_sites matcher expects params in the order searchText, size, sortOrder, sortProperty, startIndex, status — alphabetical, not the insertion order the client builds (size, startIndex, searchText, sortProperty, sortOrder, status). This only matches because aioresponses sorts query params before regex matching.

Why it matters: when these tests are ported to aiointercept (required — see the critical finding), if aiointercept matches against the raw, insertion-ordered query string instead of a sorted one, this regex (and any other multi-param matcher here) silently fails to match and the test breaks or matches the wrong mock.

How to fix: after migrating, confirm aiointercept's matching order and either keep alphabetical or rewrite the patterns to insertion order. Prefer asserting on the parsed query params rather than ordering-sensitive substring regexes.

r"searchText=Lyon.*size=5.*sortOrder=DESC.*sortProperty=Name.*startIndex=10.*status=Active"

Checklist

  • No hardcoded secrets
  • Input validation at boundaries
  • No mutable default arguments
  • New code branches tested — critical #1
  • Tests run on current main — critical #1
  • Test matching robust to framework — warning #1
  • Public API values verified — suggestion #1

To rebase specific severity levels, mention me: @bluetoothbot rebase critical (fixes 🔴 only), @bluetoothbot rebase important (fixes 🔴 + 🟡), or just @bluetoothbot rebase for all.


Automated review by Kōan (Claude) HEAD=8e29fe3 2 min 46s

@bluetoothbot bluetoothbot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blocking issues found.

  • New tests use aioresponses, which main has removed
  • Query-param regexes assume alphabetical param ordering

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds SolarEdge Monitoring API “Site Data” endpoints to the async client, plus shared helpers/types to support date/datetime coercion and bulk-site URL construction.

Changes:

  • Implemented new Site Data API methods (single-site and bulk variants) on SolarEdge.
  • Added shared helpers (_format_date, _format_datetime, _join_ids, _get_sites_url) and Literal aliases for common parameter domains.
  • Extended test coverage with new async tests for the added endpoints.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
src/aiosolaredge/solaredge.py Adds site-data endpoint wrappers plus shared helper/type infrastructure for query formatting and bulk URL building.
tests/test_init.py Adds tests covering the new endpoints and their URL/query construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_init.py
Comment on lines +126 to +130
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/sites/list\?.*"
r"searchText=Lyon.*size=5.*sortOrder=DESC.*sortProperty=Name.*"
r"startIndex=10.*status=Active"
)
Comment thread tests/test_init.py
Comment on lines +167 to +170
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/site/123/energy\?.*"
r"endDate=2013-05-30.*startDate=2013-05-01.*timeUnit=DAY"
)
Comment thread tests/test_init.py
Comment on lines +178 to +181
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/site/123/energy\?.*"
r"endDate=2013-05-30.*startDate=2013-05-01.*timeUnit=HOUR"
)
Comment thread tests/test_init.py
Comment on lines +187 to +190
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/sites/1,4/energy\?.*"
r"endDate=2013-05-30.*startDate=2013-05-01"
)
Comment thread tests/test_init.py
Comment on lines +205 to +208
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/site/123/timeFrameEnergy\?.*"
r"endDate=2013-05-06.*startDate=2013-05-01"
)
Comment thread tests/test_init.py
Comment on lines +216 to +219
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/sites/1,4/timeFrameEnergy\?.*"
r"endDate=2013-05-06.*startDate=2013-05-01"
)
Comment thread tests/test_init.py
Comment on lines +234 to +237
pattern = re.compile(
r"^https://monitoringapi\.solaredge\.com/site/123/power\?.*"
r"endTime=2013-06-04.*startTime=2013-06-04"
)
Comment on lines +16 to +19
Meter = Literal["PRODUCTION", "CONSUMPTION", "SELFCONSUMPTION", "FEEDIN", "PURCHASED"]
TimeUnit = Literal["QUARTER_OF_AN_HOUR", "HOUR", "DAY", "WEEK", "MONTH", "YEAR"]
SystemUnits = Literal["Metrics", "Imperial"]
SortOrder = Literal["ASC", "DESC"]
Comment on lines +36 to +38
def _join_ids(site_ids: Iterable[int | str]) -> str:
"""Join site IDs with a comma for bulk API calls."""
return ",".join(str(site_id) for site_id in site_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants