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

Fix todoist end time for tasks with due date in the future #91874

Merged
merged 7 commits into from May 27, 2023

Conversation

boralyl
Copy link
Contributor

@boralyl boralyl commented Apr 22, 2023

Breaking change

Proposed change

While looking into #91780 I noticed the following error when a calendar had a due date of tomorrow:

2023-04-22 20:49:26.789 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Error for call_service at pos 1: Failed to validate CalendarEvent: Expected all values to have the same timezone

This is due to having a start date in local time and comparing it to and end date in UTC. This PR addresses this but ensuring the end date is also in local time.

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 #
  • This PR is related to issue:
  • Link to documentation pull request:

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 Black (black --fast 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:

await coordinator.async_config_entry_first_refresh()
await coordinator.async_refresh()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

It is better to move setting up coordinators into the integration setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After looking at this again, I'm not exactly sure where to put this. I thought you meant within an async def async_setup function in __init__.py. But it's not clear how to get the config for a platform in that function or if platforms should have a function like that. If you could point me to an example I'd appreciate it, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the issue is that this integration should move to config entries for configuration via the UI rather than yaml. So, in addition to "ConfigEntryNotReady" not being the right error in the platform, its also not the right error if not using config entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to have this setup to support config entries in the future for sure. Perhaps after all of the bugs are fixed and it is fully working again I can take a look into that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I am not aware of straight forward way to address this (e.g. i don't know how you'd get platform specific yaml config in the integration setup). Given this fixes the immediate problem of the wrong exception being thrown, i think this is a good fix. Config entries is the right path forward in future PRs, so that sounds good.

@@ -475,16 +475,16 @@ def create_todoist_task(self, data: Task):
end = dt.parse_datetime(
data.due.datetime if data.due.datetime else data.due.date
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The start date is set to the user's local time here:

So we need to make sure this end date is also in the user's local time so that we aren't comparing local time against utc.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW i removed this restriction in a follow up PR as there are valid use cases for these differences in calendar applications. That said, i still think this is worth changing to local time.

Comment on lines 219 to 220
state = hass.states.get("calendar.all_projects")
assert state.state == "off"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assertion was actually incorrect and was only passing due to the invalid logic fixed in this PR.

@boralyl boralyl marked this pull request as ready for review April 22, 2023 21:34
@MartinHjelmare MartinHjelmare changed the title Fix end time for tasks with due date in the future. Fix todoist end time for tasks with due date in the future Apr 23, 2023
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Apr 24, 2023
@allenporter allenporter enabled auto-merge (squash) May 13, 2023 18:32
@allenporter allenporter merged commit bb170a2 into home-assistant:dev May 27, 2023
24 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2023
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.

There turns out to be something flaky here:

https://github.com/home-assistant/core/actions/runs/5116454796/jobs/9198676595#step:10:488

FAILED tests/components/todoist/test_calendar.py::test_update_entity_for_calendar_with_due_date_in_the_future[due0] - AssertionError: assert '2023-06-02 00:00:00' == '2023-06-01 00:00:00'

  • 2023-06-01 00:00:00
    ? ^
  • 2023-06-02 00:00:00
    ?

@allenporter
Copy link
Contributor

Actually, not flaky. Deterministic? I'll have a look

@allenporter
Copy link
Contributor

I've sent #93775 which may fix

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix by-code-owner cla-signed has-tests integration: todoist Quality Scale: No score small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants