Skip to content

Conversation

@victorigualada
Copy link
Contributor

Proposed change

This PR fixes a bug where the cloud integration was throwing an error when setting up ai_task and conversation, and users were not logged in to HomeAssistant Cloud.
It guards against not logged in users and handles NabuCasaBaseErrors

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: fixes AI Task log error in 2025.12.0b0 #157371
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

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

Code owner commands

Code owners of cloud can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign cloud Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@victorigualada victorigualada marked this pull request as ready for review November 27, 2025 09:16
Copilot AI review requested due to automatic review settings November 27, 2025 09:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where the cloud integration would throw errors when setting up ai_task and conversation entities for users not logged into Home Assistant Cloud. The changes add early return guards to prevent entity setup when users aren't logged in and expand error handling to catch NabuCasaBaseError exceptions.

Key changes:

  • Added early return checks for cloud.is_logged_in status in both ai_task and conversation setup functions
  • Expanded exception handling to catch NabuCasaBaseError in addition to LLMError
  • Added comprehensive test coverage for the new login check logic

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
homeassistant/components/cloud/conversation.py Added login check and expanded exception handling to prevent setup errors
homeassistant/components/cloud/ai_task.py Added login check and expanded exception handling to prevent setup errors
tests/components/cloud/test_conversation.py Added test to verify early return when not logged in
tests/components/cloud/test_ai_task.py Added test to verify early return when not logged in

@frenck frenck added this to the 2025.12.0 milestone Nov 27, 2025
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @victorigualada 👍

../Frenck

                       

Blogging my personal ramblings at frenck.dev

@MartinHjelmare MartinHjelmare changed the title return early when setting cloud ai_task and conversation and not logged in to cloud Return early when setting cloud ai_task and conversation and not logged in to cloud Nov 27, 2025
@frenck frenck merged commit 7711eac into home-assistant:dev Nov 27, 2025
66 checks passed
await cloud.llm.async_ensure_token()
except LLMError:
except (LLMError, NabuCasaBaseError):
return
Copy link
Member

Choose a reason for hiding this comment

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

Side note: It doesn't seem optimal to handle these cases here in the platform setup as there are more than one platform that needs the same checks. The state of the checks can also change after platform setup, right?

I'd only have the login checks as part of the entity available and handle the missing token as part of service action calls error cases in the entity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point in time, these 2 entities are only for internal testing, and we should not expose/set up these entities for everyone.
Once it has been decided that we are moving ahead with this for a broader audience, these setup checks will be removed as they no longer serve a purpose.

Copy link
Member

@MartinHjelmare MartinHjelmare Nov 27, 2025

Choose a reason for hiding this comment

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

Ah, ok. Then maybe move the checks to async_setup_entry in the init module and don't set up the platforms at all if the checks fail?

hass.data[DATA_CLOUD] = cloud

async_add_entities = AsyncMock()
await async_setup_entry(hass, entry, async_add_entities)
Copy link
Member

Choose a reason for hiding this comment

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

We don't test platform details directly like this.

Set up the config entry and assert (missing) state in the core state machine.

frenck pushed a commit that referenced this pull request Nov 27, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI Task log error in 2025.12.0b0

4 participants