Skip to content

Commit 8d55744

Browse files
karwostsballoob
andauthored
Add completed timestamp to TodoItem (home-assistant#156547)
Co-authored-by: Paulus Schoutsen <[email protected]>
1 parent e6e3f24 commit 8d55744

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

homeassistant/components/local_todo/todo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ async def async_update(self) -> None:
154154
),
155155
due=due,
156156
description=item.description,
157+
completed=item.completed,
157158
)
158159
)
159160
self._attr_todo_items = todo_items

homeassistant/components/todo/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ class TodoItem:
227227
description: str | None = None
228228
"""A more complete description than that provided by the summary."""
229229

230+
completed: datetime.datetime | None = None
231+
"""The date and time that a to-do item was marked completed."""
232+
230233

231234
CACHED_PROPERTIES_WITH_ATTR_ = {
232235
"todo_items",

tests/components/local_todo/snapshots/test_todo.ambr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# name: test_parse_existing_ics[completed]
33
list([
44
dict({
5+
'completed': '2023-10-25T01:40:11+00:00',
56
'status': 'completed',
67
'summary': 'Complete Task',
78
'uid': '077cb7f2-6c89-11ee-b2a9-0242ac110002',

tests/components/local_todo/test_todo.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Tests for todo platform of local_todo."""
22

33
from collections.abc import Awaitable, Callable
4+
from datetime import datetime
45
import textwrap
56
from typing import Any
67

8+
from freezegun import freeze_time
79
import pytest
810
from syrupy.assertion import SnapshotAssertion
911

@@ -19,6 +21,7 @@
1921
)
2022
from homeassistant.const import ATTR_ENTITY_ID
2123
from homeassistant.core import HomeAssistant
24+
from homeassistant.util import dt as dt_util
2225

2326
from .conftest import TEST_ENTITY
2427

@@ -239,7 +242,11 @@ async def test_bulk_remove(
239242
[
240243
(
241244
{ATTR_STATUS: "completed"},
242-
{**EXPECTED_UPDATE_ITEM, "status": "completed"},
245+
{
246+
**EXPECTED_UPDATE_ITEM,
247+
"status": "completed",
248+
"completed": "2023-11-18T08:00:00+00:00",
249+
},
243250
"0",
244251
),
245252
(
@@ -291,13 +298,15 @@ async def test_update_item(
291298
assert state.state == "1"
292299

293300
# Update item
294-
await hass.services.async_call(
295-
TODO_DOMAIN,
296-
TodoServices.UPDATE_ITEM,
297-
{ATTR_ITEM: item["uid"], **item_data},
298-
target={ATTR_ENTITY_ID: TEST_ENTITY},
299-
blocking=True,
300-
)
301+
update_time = datetime(2023, 11, 18, 8, 0, 0, tzinfo=dt_util.UTC)
302+
with freeze_time(update_time):
303+
await hass.services.async_call(
304+
TODO_DOMAIN,
305+
TodoServices.UPDATE_ITEM,
306+
{ATTR_ITEM: item["uid"], **item_data},
307+
target={ATTR_ENTITY_ID: TEST_ENTITY},
308+
blocking=True,
309+
)
301310

302311
# Verify item is updated
303312
items = await ws_get_items()
@@ -323,6 +332,7 @@ async def test_update_item(
323332
"status": "completed",
324333
"description": "Additional detail",
325334
"due": "2024-01-01",
335+
"completed": "2023-11-18T08:00:00+00:00",
326336
},
327337
),
328338
(
@@ -414,13 +424,15 @@ async def test_update_existing_field(
414424
assert item["status"] == "needs_action"
415425

416426
# Perform update
417-
await hass.services.async_call(
418-
TODO_DOMAIN,
419-
TodoServices.UPDATE_ITEM,
420-
{ATTR_ITEM: item["uid"], **item_data},
421-
target={ATTR_ENTITY_ID: TEST_ENTITY},
422-
blocking=True,
423-
)
427+
update_time = datetime(2023, 11, 18, 8, 0, 0, tzinfo=dt_util.UTC)
428+
with freeze_time(update_time):
429+
await hass.services.async_call(
430+
TODO_DOMAIN,
431+
TodoServices.UPDATE_ITEM,
432+
{ATTR_ITEM: item["uid"], **item_data},
433+
target={ATTR_ENTITY_ID: TEST_ENTITY},
434+
blocking=True,
435+
)
424436

425437
# Verify item is updated
426438
items = await ws_get_items()
@@ -618,6 +630,7 @@ async def test_move_item_previous_unknown(
618630
UID:077cb7f2-6c89-11ee-b2a9-0242ac110002
619631
CREATED:20231017T010348
620632
LAST-MODIFIED:20231024T014011
633+
COMPLETED:20231025T014011Z
621634
SEQUENCE:1
622635
STATUS:COMPLETED
623636
SUMMARY:Complete Task

tests/components/todo/test_init.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,13 +1086,15 @@ async def test_subscribe(
10861086
"status": "needs_action",
10871087
"due": None,
10881088
"description": None,
1089+
"completed": None,
10891090
},
10901091
{
10911092
"summary": "Item #2",
10921093
"uid": "2",
10931094
"status": "completed",
10941095
"due": None,
10951096
"description": None,
1097+
"completed": None,
10961098
},
10971099
]
10981100
}
@@ -1112,20 +1114,23 @@ async def test_subscribe(
11121114
"status": "needs_action",
11131115
"due": None,
11141116
"description": None,
1117+
"completed": None,
11151118
},
11161119
{
11171120
"summary": "Item #2",
11181121
"uid": "2",
11191122
"status": "completed",
11201123
"due": None,
11211124
"description": None,
1125+
"completed": None,
11221126
},
11231127
{
11241128
"summary": "Item #3",
11251129
"uid": "3",
11261130
"status": "needs_action",
11271131
"due": None,
11281132
"description": None,
1133+
"completed": None,
11291134
},
11301135
]
11311136
}

0 commit comments

Comments
 (0)