RogerSelwyn / O365-HomeAssistant

Office 365 integration for Home Assistant
MIT License
178 stars 14 forks source link

Multiple to-dos with the same name can be created #189

Closed B-Hartley closed 6 months ago

B-Hartley commented 6 months ago

Hi,

Thanks for updating the todo integration to use the HomeAssistant to-do framework, good work.

Home Assistant seems to use the subject / item name as the key to the to-do item. So I would imagine you shouldn't allow two items to be created that have the same subject. If I call add_item twice with the same item name, I get two items. If I do an update, it just updates one of them. This is a bit confusing. I think it would make sense for you to error if I ask to create an item that already exists ?

RogerSelwyn commented 6 months ago

I don’t think HA uses the subject as a key, I’d have to check. It’s been a while since I wrote that bit, but I think I pass it the identifier (guid) as the key. I wouldn’t plan to add an additional restriction on subject, I can think of use cases where people would want multiple with the same subject.

B-Hartley commented 6 months ago

ok, but the only way to update a todo item, or mark it as complete using Home Assistant service calls is by referring to it, by it's name.

I can work around it, so not the end of the world, and of course you wouldn't be able to prevent "duplicate" todos being made in other apps.

RogerSelwyn commented 6 months ago

Well, that is a rather stupid design from the core. You never use a subject as a key, and in actual fact they pass me the key in the data sent through. If HA core wants it to be unique, then they are free to add the error in their handling....

You can use o365.update_todo service which will ask for the todo_id which is visible on the todo sensor.

RogerSelwyn commented 6 months ago

Aha, I never noticed the problem before because I automatically put the todo_id in the relevant box on the HA service UI. This worked. So you can use item name/subject or todo_id.