mirror of
https://github.com/home-assistant/core.git
synced 2026-12-03 04:08:19 -04:00
Skip deleted iCloud reminder lists when creating to-do entities (#186745)
Co-authored-by: Tim Laing <timlaing@users.noreply.github.com>
This commit is contained in:
@@ -359,15 +359,15 @@ def _live_lists(service: RemindersService) -> list[tuple[str, str]]:
|
||||
list inside it can share a name, so leaving groups in shows that name
|
||||
twice, once as a permanently empty list.
|
||||
|
||||
Deleted lists leave tombstones that cannot be recognised yet. pyicloud
|
||||
exposes ``deleted`` on a reminder but not on a list, and the model forbids
|
||||
extra fields, so a tombstone is indistinguishable from an empty list until
|
||||
timlaing/pyicloud#319 is released.
|
||||
Deleted lists leave tombstones that still carry the list's name while
|
||||
holding no reminders. Sharing a list replaces its record, so every shared
|
||||
list leaves one behind: leaving them in showed a second, always empty,
|
||||
entity next to the live list.
|
||||
"""
|
||||
return [
|
||||
(reminder_list.id, reminder_list.title)
|
||||
for reminder_list in service.lists()
|
||||
if not reminder_list.is_group
|
||||
if not reminder_list.is_group and not reminder_list.deleted
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -62,13 +62,15 @@ def _reminder(
|
||||
return reminder
|
||||
|
||||
|
||||
def _list(list_id: str, title: str, *, is_group: bool = False) -> MagicMock:
|
||||
def _list(
|
||||
list_id: str, title: str, *, is_group: bool = False, deleted: bool = False
|
||||
) -> MagicMock:
|
||||
"""Build a mock pyicloud reminder list."""
|
||||
reminder_list = MagicMock()
|
||||
reminder_list.id = list_id
|
||||
reminder_list.title = title
|
||||
reminder_list.is_group = is_group
|
||||
reminder_list.deleted = False
|
||||
reminder_list.deleted = deleted
|
||||
return reminder_list
|
||||
|
||||
|
||||
@@ -167,6 +169,29 @@ async def test_groups_skipped(
|
||||
assert hass.states.get("todo.test_icloud_account_family") is None
|
||||
|
||||
|
||||
async def test_deleted_lists_skipped(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
reminders: MagicMock,
|
||||
entity_registry: er.EntityRegistry,
|
||||
) -> None:
|
||||
"""Test that a deleted list's tombstone does not become an entity.
|
||||
|
||||
Sharing a list replaces its record, so every shared list leaves a
|
||||
tombstone behind. Both records keep the list's name, so the tombstone
|
||||
showed the shared list twice, once live and once always empty.
|
||||
"""
|
||||
reminders.lists.return_value = [
|
||||
_list("list1", "Groceries"),
|
||||
_list("list2", "Groceries", deleted=True),
|
||||
]
|
||||
|
||||
await _setup(hass, config_entry)
|
||||
|
||||
entities = er.async_entries_for_config_entry(entity_registry, config_entry.entry_id)
|
||||
assert [entity.entity_id for entity in entities] == [ENTITY_ID]
|
||||
|
||||
|
||||
async def test_subtasks_follow_their_parent(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
|
||||
Reference in New Issue
Block a user