HA-Bring-ToDo-List icon indicating copy to clipboard operation
HA-Bring-ToDo-List copied to clipboard

Adding an item twice with different details only results in 1 item / error during sync

Open teranex opened this issue 2 years ago • 2 comments

When adding and item twice with different details from HA, it overwrites the first one.

Steps:

  1. in HA add 'Chips: paprika'. It correctly adds an item in Bring for Chips (crisps) with 'paprika' as the details
  2. in HA add a new item 'Chips: zout'. Instead of adding another item in Bring for Chips with details 'zout' (salt), it overwrites the 'Chips: paprika' item in Bring.

The other way around, when adding 'Chips: zout' and 'Chips: bolognaise' in Bring, results in an error in HA during sync:

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 233, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 389, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 172, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 469, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 743, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 843, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in _async_generate_attributes
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 749, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/config/custom_components/bring/todo.py", line 81, in state
    item_key = self._items.index(bring_item)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: BringTodoItem(summary='Chips:Bolognese + zout', uid='ee54c88b-8099-444e-a648-26f0fcadbcdc_item_Chips:Bolognese_+_zout', status=<TodoItemStatus.COMPLETED: 'completed'>) is not in list

teranex avatar Dec 07 '23 07:12 teranex

This is, unfortunately, a limitation with the API. Adding a new item with a different "sub title" overrides the original item.

I could fix the sync error, the problem is that updating one of them updates both. I left that as is on purpose.

sh00t2kill avatar Dec 07 '23 09:12 sh00t2kill

There is discussion about this in this thread: https://community.home-assistant.io/t/improved-shopping-list/594722/73

sh00t2kill avatar Dec 07 '23 09:12 sh00t2kill