Fix Local To-do list bug renaming items (#104182)
* Fix Local To-do bug renaming items * Fix renaming
This commit is contained in:
parent
4680ac0cbf
commit
83c59d4154
2 changed files with 51 additions and 1 deletions
|
@ -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."""
|
"""Convert TodoItem dataclass items to dictionary of attributes for ical consumption."""
|
||||||
result: dict[str, str] = {}
|
result: dict[str, str] = {}
|
||||||
for name, value in obj:
|
for name, value in obj:
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
if name == "status":
|
if name == "status":
|
||||||
result[name] = ICS_TODO_STATUS_MAP_INV[value]
|
result[name] = ICS_TODO_STATUS_MAP_INV[value]
|
||||||
elif value is not None:
|
else:
|
||||||
result[name] = value
|
result[name] = value
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,54 @@ async def test_update_item(
|
||||||
assert state.state == "0"
|
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(
|
@pytest.mark.parametrize(
|
||||||
("src_idx", "dst_idx", "expected_items"),
|
("src_idx", "dst_idx", "expected_items"),
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Reference in a new issue