Add delete service action to OneDrive integration#168064
Merged
zweckj merged 32 commits intoMay 4, 2026
Merged
Conversation
Adds the `onedrive.delete` service action that deletes a file from the OneDrive app folder. An optional `filename` field allows the local copy to be removed at the same time. Permanent deletion respects the existing `delete_permanently` config entry option.
Contributor
|
Hey there @zweckj, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
8 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new onedrive.delete service to the OneDrive integration to delete a remote file in the app folder, with an optional local-file delete.
Changes:
- Register
onedrive.deleteservice with schema (destination_pathrequired, optionalfilename) - Add localized strings + service metadata and icon for the new service
- Add test coverage for delete service happy-path and basic error cases
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/onedrive/services.py |
Implements and registers the new delete service + optional local deletion helper |
homeassistant/components/onedrive/strings.json |
Adds translated error message and service field descriptions for delete |
homeassistant/components/onedrive/services.yaml |
Declares the new delete service fields for service UI/docs |
homeassistant/components/onedrive/icons.json |
Adds an icon mapping for the delete service |
tests/components/onedrive/test_services.py |
Adds tests for remote-only delete, remote+local delete, and error cases |
- Validate destination_path: reject empty, '..', and ':' segments - Wrap Path.unlink() in OSError handler raising HomeAssistantError - Add delete_local_file_error translation key - Strengthen test assertions with full path format and delete_permanently value - Add test for delete_permanently=True option wiring
…tion - Split _delete_local_file into _validate_local_files (pre-check) and _delete_local_files (executor job after remote deletion) - Add no_delete_access_to_path translation key for local path access errors - Assert delete_drive_item not called when local path pre-validation fails
- Rename delete_error to mention OneDrive explicitly - Add delete_local_file_error, invalid_destination_path and no_delete_access_to_path translation keys to en.json - Update delete service descriptions for multi-file support
- Add vol.Length(min=1) to destination_path schema to reject empty lists - Move is_allowed_path check to event loop; offload only Path.exists() to executor - Treat FileNotFoundError in unlink() as non-fatal (race condition tolerance) - Extract _raise_invalid_destination_path helper to remove duplicate error construction - Update service name/description to reflect multi-file support - Add tests for empty destination_path and vanishing local file
21 tasks
zweckj
reviewed
Apr 28, 2026
Co-authored-by: Josef Zweck <josef@zweck.dev>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Removed specific error handling for single file deletion failure in services.py. - Updated error messages in strings.json for consistency. - Adjusted unit tests to reflect changes in error handling and message structure.
zweckj
approved these changes
May 4, 2026
Contributor
Author
|
The home-assistant/home-assistant.io#44730 should also be merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new
onedrive.deleteservice action to the OneDrive integration. This complements the existingonedrive.uploadaction, allowing users to remove files from their OneDrive app folder directly from automations.Key design decisions:
destination_path(required): one or more paths to remote files within the app folder (e.g.photos/snapshots/image.jpg), consistent with thedestination_foldernaming convention of the upload action. Multiple paths are deleted in parallel viaasyncio.gather, with allOneDriveExceptionerrors aggregated into a single translatedHomeAssistantError.delete_permanentlyoption, keeping behavior consistent with backup deletion...traversal segments, and:characters before any remote call is made.Breaking change
N/A
Proposed change
Adds the
onedrive.deleteservice action to the OneDrive integration.Type of change
Additional information
Checklist
ruff format homeassistant tests)To help with the load of incoming pull requests: