Repository navigation
Add energy site dispatch_battery_power and resume_battery_operation - #193
Conversation
Fleet API EnergySite sends teg.dispatch_battery_power_request (real_power or resume_device_mode leaf) through the grpc_command envelope. TeslemetryEnergySite calls the new Teslemetry custom routes. Both match aiopowerwall's local method names, arguments, units, sign convention and 1..86400 s duration limit, so EnergySiteRouter routes them local-first with cloud failover.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Provider commands and validation tesla_fleet_api/tesla/energysite.py, tesla_fleet_api/teslemetry/energysite.py, tests/test_energysite_battery_dispatch.py, docs/fleet_api_energy_sites.md, docs/teslemetry.md |
Fleet and Teslemetry energy sites add dispatch and resume methods. Shared validation rejects invalid power values and durations before dispatch requests. Tests check provider requests and invalid arguments. The documentation describes the commands, limits, and examples. |
Router dispatch and fallback tests/test_energysite_battery_dispatch.py |
Tests verify local-first dispatch and resume calls, and cloud fallback when local calls raise ConnectionError. |
Priority:
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant EnergySiteRouter
participant LocalEnergySite
participant TeslemetryEnergySite
participant FleetEnergySite
EnergySiteRouter->>LocalEnergySite: dispatch or resume
alt Local call succeeds
LocalEnergySite-->>EnergySiteRouter: result
else Local call raises ConnectionError
alt Teslemetry fallback
EnergySiteRouter->>TeslemetryEnergySite: dispatch or resume
TeslemetryEnergySite-->>EnergySiteRouter: result
else Fleet fallback
EnergySiteRouter->>FleetEnergySite: dispatch or resume
FleetEnergySite-->>EnergySiteRouter: result
end
end
Merge Risk: 
Minimal · up to 4d13d
-
No actionable merge-blocking risk was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the two new public methods, dispatch_battery_power and resume_battery_operation, on the energy site classes. The raw summary and PR objectives confirm these methods are the main change, so the title matches the changeset. It is specific and concise.
Full details: Description check
-
Explanation
The description states that the PR adds dispatch_battery_power and resume_battery_operation to the energy site classes. It also covers the Fleet API endpoint, Teslemetry routes, router compatibility with aiopowerwall, tests, and the follow-up work outside this repo. It is closely related to the changeset.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 16.67% 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 6 functions across 3 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches: 💡 1
-
📝 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
Comment @coderabbitai help to get the list of available commands.
Summary
Adds
dispatch_battery_power(power_watts, duration_seconds)andresume_battery_operation()to the energy site classes.EnergySite(Tesla Fleet API): sendsPOST /api/1/energy_sites/{id}/commandwith thegrpc_commandenvelope,identifier_type1 (gateway DIN). The message isteg.dispatch_battery_power_requestwith areal_powerleaf (power_watts,duration_seconds) or aresume_device_modeleaf. Needs theenergy_cmdsscope.TeslemetryEnergySite: calls the Teslemetry routesPOST .../command/dispatch_battery_power(body{"power_watts", "duration_seconds"}) andPOST .../command/resume_battery_operation, added in Teslemetry/api#886.validate_dispatch_battery_powercopies aiopowerwall's checks, so each backend raises the sameValueErrorbefore any request.EnergySiteRouteralready routes any method that both backends have throughRouter.__getattr__, the same way it routesoperation()andbackup(). Sorouter/energysite.pyneeds no code change: it tries the local primary first and fails over to the cloud with the same arguments.A failover that repeats
dispatch_battery_poweris safe. A new call replaces the active setpoint (power and timer), and resume is idempotent.Follow-up outside this repo
aiopowerwall's
PowerwallEnergySiteadapter (the router's local primary) does not expose these two methods yet; onlyPowerwallClienthas them. Until the adapter gets them,EnergySiteRoutersends both commands to the cloud backend.Tests
tests/test_energysite_battery_dispatch.py: the exact request bodies for both classes, 12 invalid argument pairs that raise without a request, signature parity with an aiopowerwall-shaped local site, and router routing (local first, cloud failover to Teslemetry and to Fleet gRPC).testgate uv run pytest tests/test_energysite_battery_dispatch.py tests/test_router.py tests/test_energysite_island_mode.py: 50 passeduv run pyright tesla_fleet_api: 0 errorsuv run ruff check: cleanNo live command was sent from this change. The captain has confirmation that the cloud command works.