Skip to content

Add Tesla Fleet Energy Site read-only profile - #181366

Draft
WhiteStoneTak wants to merge 1 commit into
home-assistant:devfrom
WhiteStoneTak:codex/tesla-energy-site-read-only
Draft

Add Tesla Fleet Energy Site read-only profile#181366
WhiteStoneTak wants to merge 1 commit into
home-assistant:devfrom
WhiteStoneTak:codex/tesla-energy-site-read-only

Conversation

@WhiteStoneTak

@WhiteStoneTak WhiteStoneTak commented Sep 5, 2026

Copy link
Copy Markdown

Proposed change

Add an authorization-profile choice to Tesla Fleet before OAuth. The existing Standard profile remains the default and preserves the current scope request and runtime behavior, including for existing entries that do not have a stored profile. The new Energy Site read-only profile requests exactly openid, offline_access, and energy_device_data; it does not request energy_cmds or any vehicle scope.

The selected profile is stored in the config entry and retained during reauthentication. Energy Site read-only tokens are validated after OAuth, during setup, and whenever the current access token is obtained. This profile does not construct vehicle clients or coordinators, forwards only sensor and binary sensor platforms, and retains only a narrow Energy API facade for site information, live status, and energy history. It exposes no writable Energy path. Energy history retains the integration's existing five-minute cadence and existing Energy Site sensor behavior.

Local validation passed: all 193 Tesla Fleet tests and 425 snapshots, Ruff check and format, hassfest, full Core and Tesla Fleet component mypy, and change-scoped hooks. No real Tesla OAuth or production deployment was performed.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: N/A
  • This PR is related to issue: N/A
  • Link to documentation pull request: Pending; the documentation patch is prepared locally but no documentation PR has been opened.
  • Link to developer documentation pull request: N/A
  • Link to frontend pull request: N/A

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running: python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI balanced review requested due to automatic review settings September 5, 2026 08:34

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @WhiteStoneTak

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant

home-assistant Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
home-assistant Bot marked this pull request as draft September 5, 2026 08:34
@home-assistant

home-assistant Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Hey there @Bre77, mind taking a look at this pull request as it has been labeled with an integration (tesla_fleet) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tesla_fleet can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign tesla_fleet Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The read-only completion path needs public config-flow coverage; documentation, description, and reauthentication messaging also need updates.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a Tesla Fleet Energy Site read-only authorization profile with restricted scopes and telemetry-only entities.

Changes:

  • Adds profile selection and OAuth scope validation.
  • Restricts read-only entries to energy telemetry APIs and platforms.
  • Adds setup, reauthentication, and validation tests.
File summaries
File Description
tests/components/tesla_fleet/test_init.py Tests restricted setup behavior.
tests/components/tesla_fleet/test_config_flow.py Tests profile OAuth and reauthentication flows.
tests/components/tesla_fleet/conftest.py Adds read-only test fixtures.
homeassistant/components/tesla_fleet/strings.json Adds profile UI strings and errors.
homeassistant/components/tesla_fleet/oauth.py Validates exact read-only scopes.
homeassistant/components/tesla_fleet/models.py Adds the read-only Energy Site facade.
homeassistant/components/tesla_fleet/const.py Defines profiles and scope mappings.
homeassistant/components/tesla_fleet/config_flow.py Adds profile selection and OAuth handling.
homeassistant/components/tesla_fleet/__init__.py Enforces profile restrictions during setup.
Review details

Suppressed comments (2)

homeassistant/components/tesla_fleet/strings.json:6

  • Use an abort message that also applies during reauthentication. This reason is returned for both initial setup and SOURCE_REAUTH, so “No integration entry was created” is false when an existing read-only entry fails reauthentication.
      "invalid_energy_site_read_only_scopes": "Tesla did not grant exactly the scopes required by the Energy Site read-only profile. No integration entry was created.",

homeassistant/components/tesla_fleet/strings.json:77

  • Add and link the required documentation update for this user-facing profile. The new selection changes requested permissions and available devices/entities, but the PR description leaves the documentation link blank, so users will have no integration documentation for choosing or understanding it.
        "description": "The **Standard** profile supports vehicles and energy sites, including commands and settings. The **Energy Site read-only** profile requests Energy telemetry only. It cannot access vehicles or change Energy settings.",
  • Files reviewed: 9/9 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +470 to +474
flow = OAuth2FlowHandler()
flow.hass = hass
flow.api = AsyncMock()
flow.api.private_key = Mock()
flow.api.public_uncompressed_point = "expected-public-key"
Comment on lines +313 to +316
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Select an authorization profile before starting OAuth."""
@Bre77

Bre77 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

I thought if you simply don't provide energy commands when connecting Tesla the integration should work and respect that choice. Is that not the case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants