Skip to content

Commit 25cc4df

Browse files
authored
Fix Local To-do list bug renaming items (home-assistant#104182)
* Fix Local To-do bug renaming items * Fix renaming
1 parent 9a38e23 commit 25cc4df

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

homeassistant/components/local_todo/todo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ def _todo_dict_factory(obj: Iterable[tuple[str, Any]]) -> dict[str, str]:
6363
"""Convert TodoItem dataclass items to dictionary of attributes for ical consumption."""
6464
result: dict[str, str] = {}
6565
for name, value in obj:
66+
if value is None:
67+
continue
6668
if name == "status":
6769
result[name] = ICS_TODO_STATUS_MAP_INV[value]
68-
elif value is not None:
70+
else:
6971
result[name] = value
7072
return result
7173

tests/components/local_todo/test_todo.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,54 @@ async def test_update_item(
237237
assert state.state == "0"
238238

239239

240+
async def test_rename(
241+
hass: HomeAssistant,
242+
setup_integration: None,
243+
ws_get_items: Callable[[], Awaitable[dict[str, str]]],
244+
) -> None:
245+
"""Test renaming a todo item."""
246+
247+
# Create new item
248+
await hass.services.async_call(
249+
TODO_DOMAIN,
250+
"add_item",
251+
{"item": "soda"},
252+
target={"entity_id": TEST_ENTITY},
253+
blocking=True,
254+
)
255+
256+
# Fetch item
257+
items = await ws_get_items()
258+
assert len(items) == 1
259+
item = items[0]
260+
assert item["summary"] == "soda"
261+
assert item["status"] == "needs_action"
262+
263+
state = hass.states.get(TEST_ENTITY)
264+
assert state
265+
assert state.state == "1"
266+
267+
# Rename item
268+
await hass.services.async_call(
269+
TODO_DOMAIN,
270+
"update_item",
271+
{"item": item["uid"], "rename": "water"},
272+
target={"entity_id": TEST_ENTITY},
273+
blocking=True,
274+
)
275+
276+
# Verify item has been renamed
277+
items = await ws_get_items()
278+
assert len(items) == 1
279+
item = items[0]
280+
assert item["summary"] == "water"
281+
assert item["status"] == "needs_action"
282+
283+
state = hass.states.get(TEST_ENTITY)
284+
assert state
285+
assert state.state == "1"
286+
287+
240288
@pytest.mark.parametrize(
241289
("src_idx", "dst_idx", "expected_items"),
242290
[

0 commit comments

Comments
 (0)