Fix Local To-do list bug renaming items (#104182)

* Fix Local To-do bug renaming items

* Fix renaming
This commit is contained in:
Allen Porter 2023-11-19 11:26:58 -08:00 committed by GitHub
parent 9a38e23f28
commit 25cc4df455
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View file

@ -63,9 +63,11 @@ def _todo_dict_factory(obj: Iterable[tuple[str, Any]]) -> dict[str, str]:
"""Convert TodoItem dataclass items to dictionary of attributes for ical consumption."""
result: dict[str, str] = {}
for name, value in obj:
if value is None:
continue
if name == "status":
result[name] = ICS_TODO_STATUS_MAP_INV[value]
elif value is not None:
else:
result[name] = value
return result

View file

@ -237,6 +237,54 @@ async def test_update_item(
assert state.state == "0"
async def test_rename(
hass: HomeAssistant,
setup_integration: None,
ws_get_items: Callable[[], Awaitable[dict[str, str]]],
) -> None:
"""Test renaming a todo item."""
# Create new item
await hass.services.async_call(
TODO_DOMAIN,
"add_item",
{"item": "soda"},
target={"entity_id": TEST_ENTITY},
blocking=True,
)
# Fetch item
items = await ws_get_items()
assert len(items) == 1
item = items[0]
assert item["summary"] == "soda"
assert item["status"] == "needs_action"
state = hass.states.get(TEST_ENTITY)
assert state
assert state.state == "1"
# Rename item
await hass.services.async_call(
TODO_DOMAIN,
"update_item",
{"item": item["uid"], "rename": "water"},
target={"entity_id": TEST_ENTITY},
blocking=True,
)
# Verify item has been renamed
items = await ws_get_items()
assert len(items) == 1
item = items[0]
assert item["summary"] == "water"
assert item["status"] == "needs_action"
state = hass.states.get(TEST_ENTITY)
assert state
assert state.state == "1"
@pytest.mark.parametrize(
("src_idx", "dst_idx", "expected_items"),
[