You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add grid export/import limit and solar curtailment commands for energy sites - #219
Adds the Powerwall grid export limit, grid import limit and on-grid solar curtailment commands to the cloud energy sites, alongside the existing LAN PowerwallClient methods: get_config_json(), set_config_json(min_site_meter_power_ac, max_site_meter_power_ac, on_grid_solar_curtailment_enabled), and set_export_limit, set_import_limit and set_on_grid_solar_curtailment, which have the LAN client's names and units. A keyless TeslemetryEnergySite calls Teslemetry's GET/POST command/config_json routes. With a signing key, both EnergySite and TeslemetryEnergySite sign a filestore read of config.json, then an update_file with the hash from that read, through device_command, and return the same {min_site_meter_power_ac, max_site_meter_power_ac, on_grid_solar_curtailment_enabled, applied} readback as the route. A Fleet API site without a key raises SignedCommandRequired, because Tesla refuses unsigned device commands. The field bounds (kW; export as negative site-meter power from -1000 to 0, import from 0 to 1000) are the route's, checked before any request. Covered by unit tests with mocked HTTP only; the signed cloud filestore path has not been tried on a live gateway.
No actionable comments were generated in the recent review.
Walkthrough
Energy-site classes add config.json read and write operations for grid import and export limits and on-grid solar curtailment. Fleet API operations use signed commands and validate settings before requests. Teslemetry operations use its routes when no client signing key is configured.
Changes: Energy-site config.json
Layer / File(s)
Summary
Signed config operations tesla_fleet_api/tesla/energysite.py, tests/test_energysite_config_json.py, docs/fleet_api_energy_sites.md
EnergySite validates setting values, reads config.json and its hash, and updates only requested site_info keys. It skips writes when values match and reports whether returned settings match. Tests cover signed requests, validation, unchanged settings, readback, and malformed replies. Fleet API documentation describes the methods and signed-command requirements.
TeslemetryEnergySite delegates to signed EnergySite methods when a signing key is present. Without one, it uses Teslemetry config_json routes. Tests and documentation cover those routes.
sequenceDiagram
participant Caller
participant TeslemetryEnergySite
participant EnergySite
participant Teslemetry_config_json_route
Caller->>TeslemetryEnergySite: Request config read or update
alt Client signing key is present
TeslemetryEnergySite->>EnergySite: Delegate config operation
EnergySite-->>TeslemetryEnergySite: Return config result
else No client signing key
TeslemetryEnergySite->>Teslemetry_config_json_route: GET or POST config_json
Teslemetry_config_json_route-->>TeslemetryEnergySite: Return route response
end
TeslemetryEnergySite-->>Caller: Return config result
No actionable issue was established before merge. The signed cloud path has not been tested on a live gateway.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description check
The description directly explains the added energy-site commands, signing behavior, validation limits, routes, and test coverage.
Title check
The title clearly and concisely identifies the main change: adding grid export and import limits and solar curtailment commands for energy sites.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 3 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.
Reviewing files that changed from the base of the PR and between 067b39c and 3b2c404.
Files selected for processing: 5
docs/fleet_api_energy_sites.md
docs/teslemetry.md
tesla_fleet_api/tesla/energysite.py
tesla_fleet_api/teslemetry/energysite.py
tests/test_energysite_config_json.py
Limit details: You’ve used the included review currently available. Your 101 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the Powerwall grid export limit, grid import limit and on-grid solar curtailment commands to the cloud energy sites, alongside the existing LAN
PowerwallClientmethods:get_config_json(),set_config_json(min_site_meter_power_ac, max_site_meter_power_ac, on_grid_solar_curtailment_enabled), andset_export_limit,set_import_limitandset_on_grid_solar_curtailment, which have the LAN client's names and units. A keylessTeslemetryEnergySitecalls Teslemetry'sGET/POST command/config_jsonroutes. With a signing key, bothEnergySiteandTeslemetryEnergySitesign a filestore read of config.json, then anupdate_filewith the hash from that read, throughdevice_command, and return the same{min_site_meter_power_ac, max_site_meter_power_ac, on_grid_solar_curtailment_enabled, applied}readback as the route. A Fleet API site without a key raisesSignedCommandRequired, because Tesla refuses unsigned device commands. The field bounds (kW; export as negative site-meter power from -1000 to 0, import from 0 to 1000) are the route's, checked before any request. Covered by unit tests with mocked HTTP only; the signed cloud filestore path has not been tried on a live gateway.