mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add completed timestamp to TodoItem (#156547)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
@@ -154,6 +154,7 @@ class LocalTodoListEntity(TodoListEntity):
|
||||
),
|
||||
due=due,
|
||||
description=item.description,
|
||||
completed=item.completed,
|
||||
)
|
||||
)
|
||||
self._attr_todo_items = todo_items
|
||||
|
||||
@@ -227,6 +227,9 @@ class TodoItem:
|
||||
description: str | None = None
|
||||
"""A more complete description than that provided by the summary."""
|
||||
|
||||
completed: datetime.datetime | None = None
|
||||
"""The date and time that a to-do item was marked completed."""
|
||||
|
||||
|
||||
CACHED_PROPERTIES_WITH_ATTR_ = {
|
||||
"todo_items",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# name: test_parse_existing_ics[completed]
|
||||
list([
|
||||
dict({
|
||||
'completed': '2023-10-25T01:40:11+00:00',
|
||||
'status': 'completed',
|
||||
'summary': 'Complete Task',
|
||||
'uid': '077cb7f2-6c89-11ee-b2a9-0242ac110002',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"""Tests for todo platform of local_todo."""
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from datetime import datetime
|
||||
import textwrap
|
||||
from typing import Any
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
@@ -19,6 +21,7 @@ from homeassistant.components.todo import (
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .conftest import TEST_ENTITY
|
||||
|
||||
@@ -239,7 +242,11 @@ EXPECTED_UPDATE_ITEM = {
|
||||
[
|
||||
(
|
||||
{ATTR_STATUS: "completed"},
|
||||
{**EXPECTED_UPDATE_ITEM, "status": "completed"},
|
||||
{
|
||||
**EXPECTED_UPDATE_ITEM,
|
||||
"status": "completed",
|
||||
"completed": "2023-11-18T08:00:00+00:00",
|
||||
},
|
||||
"0",
|
||||
),
|
||||
(
|
||||
@@ -291,13 +298,15 @@ async def test_update_item(
|
||||
assert state.state == "1"
|
||||
|
||||
# Update item
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
{ATTR_ITEM: item["uid"], **item_data},
|
||||
target={ATTR_ENTITY_ID: TEST_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
update_time = datetime(2023, 11, 18, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
with freeze_time(update_time):
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
{ATTR_ITEM: item["uid"], **item_data},
|
||||
target={ATTR_ENTITY_ID: TEST_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
# Verify item is updated
|
||||
items = await ws_get_items()
|
||||
@@ -323,6 +332,7 @@ async def test_update_item(
|
||||
"status": "completed",
|
||||
"description": "Additional detail",
|
||||
"due": "2024-01-01",
|
||||
"completed": "2023-11-18T08:00:00+00:00",
|
||||
},
|
||||
),
|
||||
(
|
||||
@@ -414,13 +424,15 @@ async def test_update_existing_field(
|
||||
assert item["status"] == "needs_action"
|
||||
|
||||
# Perform update
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
{ATTR_ITEM: item["uid"], **item_data},
|
||||
target={ATTR_ENTITY_ID: TEST_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
update_time = datetime(2023, 11, 18, 8, 0, 0, tzinfo=dt_util.UTC)
|
||||
with freeze_time(update_time):
|
||||
await hass.services.async_call(
|
||||
TODO_DOMAIN,
|
||||
TodoServices.UPDATE_ITEM,
|
||||
{ATTR_ITEM: item["uid"], **item_data},
|
||||
target={ATTR_ENTITY_ID: TEST_ENTITY},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
# Verify item is updated
|
||||
items = await ws_get_items()
|
||||
@@ -618,6 +630,7 @@ async def test_move_item_previous_unknown(
|
||||
UID:077cb7f2-6c89-11ee-b2a9-0242ac110002
|
||||
CREATED:20231017T010348
|
||||
LAST-MODIFIED:20231024T014011
|
||||
COMPLETED:20231025T014011Z
|
||||
SEQUENCE:1
|
||||
STATUS:COMPLETED
|
||||
SUMMARY:Complete Task
|
||||
|
||||
@@ -1086,6 +1086,7 @@ async def test_subscribe(
|
||||
"status": "needs_action",
|
||||
"due": None,
|
||||
"description": None,
|
||||
"completed": None,
|
||||
},
|
||||
{
|
||||
"summary": "Item #2",
|
||||
@@ -1093,6 +1094,7 @@ async def test_subscribe(
|
||||
"status": "completed",
|
||||
"due": None,
|
||||
"description": None,
|
||||
"completed": None,
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -1112,6 +1114,7 @@ async def test_subscribe(
|
||||
"status": "needs_action",
|
||||
"due": None,
|
||||
"description": None,
|
||||
"completed": None,
|
||||
},
|
||||
{
|
||||
"summary": "Item #2",
|
||||
@@ -1119,6 +1122,7 @@ async def test_subscribe(
|
||||
"status": "completed",
|
||||
"due": None,
|
||||
"description": None,
|
||||
"completed": None,
|
||||
},
|
||||
{
|
||||
"summary": "Item #3",
|
||||
@@ -1126,6 +1130,7 @@ async def test_subscribe(
|
||||
"status": "needs_action",
|
||||
"due": None,
|
||||
"description": None,
|
||||
"completed": None,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user