Fix tasks with no due date from not triggering on calendar state. (#91196)

Fix tasks with no due date.

Prior to this change we were setting the start date/time to utc rather
than the user's timezone.
This commit is contained in:
Aaron Godfrey 2023-04-13 21:12:58 -07:00 committed by GitHub
parent 0ddccb26fa
commit 7061b104a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 1 deletions

View File

@ -446,7 +446,7 @@ class TodoistProjectData:
LABELS: [],
OVERDUE: False,
PRIORITY: data.priority,
START: dt.utcnow(),
START: dt.now(),
SUMMARY: data.content,
}

View File

@ -25,6 +25,14 @@ from homeassistant.util import dt
from tests.typing import ClientSessionGenerator
@pytest.fixture(autouse=True)
def set_time_zone(hass: HomeAssistant):
"""Set the time zone for the tests."""
# Set our timezone to CST/Regina so we can check calculations
# This keeps UTC-6 all year round
hass.config.set_time_zone("America/Regina")
@pytest.fixture(name="task")
def mock_task() -> Task:
"""Mock a todoist Task instance."""
@ -132,6 +140,52 @@ async def test_update_entity_for_custom_project_with_labels_on(
assert state.state == "on"
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
async def test_update_entity_for_custom_project_no_due_date_on(
todoist_api, hass: HomeAssistant, api
) -> None:
"""Test that a task without an explicit due date is considered to be in an on state."""
task_wo_due_date = Task(
assignee_id=None,
assigner_id=None,
comment_count=0,
is_completed=False,
content="No due date task",
created_at="2023-04-11T00:25:25.589971Z",
creator_id="1",
description="",
due=None,
id="123",
labels=["Label1"],
order=10,
parent_id=None,
priority=1,
project_id="12345",
section_id=None,
url="https://todoist.com/showTask?id=123",
sync_id=None,
)
api.get_tasks.return_value = [task_wo_due_date]
todoist_api.return_value = api
assert await setup.async_setup_component(
hass,
"calendar",
{
"calendar": {
"platform": DOMAIN,
CONF_TOKEN: "token",
"custom_projects": [{"name": "All projects", "labels": ["Label1"]}],
}
},
)
await hass.async_block_till_done()
await async_update_entity(hass, "calendar.all_projects")
state = hass.states.get("calendar.all_projects")
assert state.state == "on"
@patch("homeassistant.components.todoist.calendar.TodoistAPIAsync")
async def test_failed_coordinator_update(todoist_api, hass: HomeAssistant, api) -> None:
"""Test a failed data coordinator update is handled correctly."""