New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add todo component #100019
Add todo component #100019
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
22fc591
to
2a3e24e
Compare
Marking as draft until we complete a round of user research to make sure the proposal has all the requirements. I think the APIs are still mostly correct here, but marking to indicate the actual status. |
ffc4784
to
1fedcb8
Compare
1fedcb8
to
a929d0d
Compare
"""Add an item to the To-do list.""" | ||
raise NotImplementedError() | ||
|
||
async def async_delete_todo_items(self, uids: set[str]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use a set parameter with multiple uids to follow the rfc spec or why do we use multiple instead of a single item for this action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is purely for practical performance concerns, not related to the rfc spec.
When reviewing the shopping list API, one observation was that we currently require a "clear completed items" for the shopping list. This is also part of the new spec for todo when I looked at the wireframes shared by Bram that Madelena made. (This is mentioned in home-assistant/architecture#962 in passing under "Consequences" as a performance topic)
An alternative could be to rename this "clear completed items" rather than supporting delete of arbitrary items, however then i believe it requires more custom logic by the integration to implement. I liked simplifying this by pushing this to be a frontend concern about which items it is deleting (delete is needed anyway) allowing cloud integrations to have a more straight forward API.
Open to suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made two API changes based on offline discussion for FE concerns:
- The move service was reverted back to a websocket to be frontend focused (also lower priority for end user service)
- The move service was simplified to take a position rather than a previous item. This pushes complexity into integrations that need to handle relative positions rather than in the frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Is codecov correct that some lines are not covered? Can we test those in that case?
Looks legit. I updated todo component with additional tests. The shopping list case for unloaded is not tested, but the code is still there. One option is to just remove this code since shopping list does not yet support unload, though it feels weird to leave it incomplete. |
I don't see the code regarding unload in the shopping list integration. |
There is code in
And so the add listener unsub code in shopping list turned out to be not actually used given shopping list todo entities cannot be unloaded. (I thought the code I just added added coverage in todo, but it didn't so i reverted it. the code coverage is similar to event now at least) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add back the unload tests for todo integration. Add a mock entity that should be removed or unavailable when the config entry is unloaded. That way we know that we've hooked up the todo integration to the entity component helper correctly.
Example:
core/tests/components/lawn_mower/test_init.py
Lines 62 to 126 in ab29c79
async def test_lawn_mower_setup(hass: HomeAssistant) -> None: | |
"""Test setup and tear down of lawn mower platform and entity.""" | |
async def async_setup_entry_init( | |
hass: HomeAssistant, config_entry: ConfigEntry | |
) -> bool: | |
"""Set up test config entry.""" | |
await hass.config_entries.async_forward_entry_setup( | |
config_entry, Platform.LAWN_MOWER | |
) | |
return True | |
async def async_unload_entry_init( | |
hass: HomeAssistant, config_entry: ConfigEntry | |
) -> bool: | |
"""Unload up test config entry.""" | |
await hass.config_entries.async_unload_platforms( | |
config_entry, [Platform.LAWN_MOWER] | |
) | |
return True | |
mock_platform(hass, f"{TEST_DOMAIN}.config_flow") | |
mock_integration( | |
hass, | |
MockModule( | |
TEST_DOMAIN, | |
async_setup_entry=async_setup_entry_init, | |
async_unload_entry=async_unload_entry_init, | |
), | |
) | |
entity1 = MockLawnMowerEntity() | |
entity1.entity_id = "lawn_mower.mock_lawn_mower" | |
async def async_setup_entry_platform( | |
hass: HomeAssistant, | |
config_entry: ConfigEntry, | |
async_add_entities: AddEntitiesCallback, | |
) -> None: | |
"""Set up test platform via config entry.""" | |
async_add_entities([entity1]) | |
mock_platform( | |
hass, | |
f"{TEST_DOMAIN}.{LAWN_MOWER_DOMAIN}", | |
MockPlatform(async_setup_entry=async_setup_entry_platform), | |
) | |
config_entry = MockConfigEntry(domain=TEST_DOMAIN) | |
config_entry.add_to_hass(hass) | |
assert await hass.config_entries.async_setup(config_entry.entry_id) | |
await hass.async_block_till_done() | |
assert config_entry.state == ConfigEntryState.LOADED | |
assert hass.states.get(entity1.entity_id) | |
assert await hass.config_entries.async_unload(config_entry.entry_id) | |
await hass.async_block_till_done() | |
assert config_entry.state == ConfigEntryState.NOT_LOADED | |
entity_state = hass.states.get(entity1.entity_id) | |
assert entity_state | |
assert entity_state.state == STATE_UNAVAILABLE |
Thank you, I was missing the call to |
Can be merged when there's a linked and approved frontend PR. |
Proposed change
Add todo component. Updates the Shopping List component to implement the todo platform. This platform was also manually tested with a local todo implementation (removed as it is a larger scope PR, so local todo list based on rfc5545 will come in followups).
The to-do list platform registers the existing shopping list frontend panel (can be updated based on frontend PR direction)
An alternative can be to import shopping list into a local todo list component, though we can probably do that in followup PRs if desired.
Type of change
Additional information
Link to frontend pull request: Add todo component that supports multiple To-do lists. frontend#17883Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: