Skip to content

Move service registration to async_setup in Todoist - #175759

Merged
joostlek merged 2 commits into
home-assistant:devfrom
some-random-climber:todoist
Jul 29, 2026
Merged

Move service registration to async_setup in Todoist#175759
joostlek merged 2 commits into
home-assistant:devfrom
some-random-climber:todoist

Conversation

@some-random-climber

@some-random-climber some-random-climber commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Proposed change

Move service registration to async_setup in Todoist.

Todoist still supports the legacy YAML calendar platform (platform: todoist), which creates a coordinator without a config entry. Because of that, the new_task service cannot rely solely on async_get_config_entry. The YAML coordinator is now exposed through hass.data and preferred by the service handler, which falls back to the single loaded config entry otherwise. This keeps the service working for both YAML and config-entry setups.

Part of home-assistant/epics#65

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

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 review requested due to automatic review settings July 6, 2026 09:57
@home-assistant

home-assistant Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of todoist 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 todoist 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.

Pull request overview

This PR refactors the Todoist integration to register its new_task service from the integration-level async_setup (via a new services.py module) instead of registering it inside the calendar platform's async_setup_entry/async_setup_platform. This makes the service available even when no config entry is loaded, so Home Assistant can validate automations that reference todoist.new_task. It is part of the epic to move service registration to async_setup (home-assistant/epics#65) and addresses issue #170752.

Changes:

  • Added homeassistant/components/todoist/services.py containing the new_task schema, handler, and a @callback async_setup_services helper that resolves the config entry at call time via service.async_get_config_entry.
  • Registered services once from a new async_setup in __init__.py and added CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN).
  • Removed the service schema, handler, and async_register_services (plus now-unused imports) from calendar.py.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/todoist/services.py New module holding the moved new_task service schema/handler and async_setup_services; handler now looks up the config entry dynamically.
homeassistant/components/todoist/init.py Adds async_setup that registers services once and declares CONFIG_SCHEMA.
homeassistant/components/todoist/calendar.py Removes the service schema, handler, async_register_services, and the now-unused imports.

Holistic assessment: The refactor follows the established pattern (e.g. Cloudflare, Amber Electric) and the code move itself is clean, with imports correctly pruned in calendar.py. However, Todoist still fully supports the legacy YAML calendar platform (async_setup_platform), which never creates a config entry. Because the new handler resolves the config entry via service.async_get_config_entry(..., None), todoist.new_task will fail for YAML-only setups, and the existing service tests (which run through the autouse YAML setup_platform fixture) will break. This needs to be resolved before merging.

Comment thread homeassistant/components/todoist/services.py Outdated
The legacy YAML calendar platform creates a coordinator without a config
entry, so resolving it through async_get_config_entry fails. Expose the
YAML coordinator through hass.data and prefer it in the service handler,
falling back to the single loaded config entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 9, 2026 11:33

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@epenet
epenet marked this pull request as ready for review July 9, 2026 11:34
@joostlek
joostlek merged commit c498d4f into home-assistant:dev Jul 29, 2026
32 of 33 checks passed
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.

Move service registration to async_setup in todoist

4 participants