Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send recurrence data when updating a task in todoist #108269

Merged
merged 8 commits into from Jan 21, 2024

Conversation

boralyl
Copy link
Contributor

@boralyl boralyl commented Jan 18, 2024

Breaking change

Proposed change

This fixes an issue where marking a recurring task as completed using the todo domain would cause the recurrence data to be erased in todoist. See the issue for further information.

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

  • 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.

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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

"content": "Soda",
"description": "6-pack",
"due_date": "2024-02-01",
"due_string": "every day",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And verifying that it ends up getting passed as a kwarg when updating the task.

@boralyl boralyl marked this pull request as ready for review January 18, 2024 01:38
tests/components/todoist/test_todo.py Show resolved Hide resolved
tests/components/todoist/test_todo.py Show resolved Hide resolved
api_data = next((d for d in self.coordinator.data if d.id == uid), None)
if api_data is not None:
if due := api_data.due:
update_data["due_string"] = due.string
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this only be set when due_string was already present?

Copy link
Contributor Author

@boralyl boralyl Jan 18, 2024

Choose a reason for hiding this comment

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

If you set a due date/datetime this will always be set in my testing with the api responses.

No due date:

{
  "due": null
}

Due date:

{
  "due": {
        "date": "2024-01-17",
        "is_recurring": false,
        "lang": "en",
        "string": "Jan 17"
    }
}

Due date/time:

{
  "due": {
        "date": "2024-01-17",
        "datetime": "2024-01-17T21:30:00",
        "is_recurring": false,
        "lang": "en",
        "string": "Jan 17 9:30 PM"

    }
}

Due date recurring:

{
  "due": {
        "date": "2024-01-17",
        "is_recurring": true,
        "lang": "en",
        "string": "every day"

    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, makes sense.

What should happen to the due string when due date is being changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great question. I decided to move the logic inside of _task_api_data to avoid the situation where previously it would overwrite the due_string if the user had tried to unset it.

From testing it appears the due_date and due_datetime parameters take precedence over due_string if they don't match in the case where there is no recurrence. For example this data POSTed to the endpoint when changing the due date from 2024-01-18 to 2024-01-31:

{
  "content": "test",
  "description": "",
  "due_date": "2024-01-31",
  "due_string": "Jan 18"
}

And the task is updated correctly in todoist with the new due date of 2024-01-31.

@home-assistant home-assistant bot marked this pull request as draft January 18, 2024 04:20
@home-assistant
Copy link

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.

@boralyl boralyl marked this pull request as ready for review January 18, 2024 05:41
Copy link
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

Looks great! 👍🏼

@allenporter allenporter merged commit 71e6365 into home-assistant:dev Jan 21, 2024
23 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
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.

Todoist recurring tasks are deleted when completed by the todo update_item service
2 participants