Skip to content

Add grid export/import limit and solar curtailment commands for energy sites - #219

Merged
Bre77 merged 1 commit into
mainfrom
fm/fm-35
Nov 4, 2026
Merged

Bre77 merged 1 commit into
mainfrom
fm/fm-35

Conversation

@Bre77

@Bre77 Bre77 commented Nov 4, 2026

Copy link
Copy Markdown
Member

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.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Explain Change →

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.
Teslemetry config routes
tesla_fleet_api/teslemetry/energysite.py, tests/test_energysite_config_json.py, docs/teslemetry.md
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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

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
Loading

Possibly related PRs

Merge Risk: Minimal · up to 3b2c4

No actionable issue was established before merge. The signed cloud path has not been tested on a live gateway.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description directly explains the added energy-site commands, signing behavior, validation limits, routes, and test coverage.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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

Usage-based review receipt

Note

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.

Recent review info
Run configuration
Commits

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.

@Bre77
Bre77 merged commit 0dd419b into main Nov 4, 2026
7 checks passed
@Bre77
Bre77 deleted the fm/fm-35 branch November 4, 2026 06:39
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.

1 participant