Home Assistant integration
This integration connects one user's TasksNest grocery list and, optionally, one planner task list to separate Home Assistant todo.* entities. The user configures the URL and long-lived access token at /settings/home-assistant/, tests the connection, discovers entities, chooses lists, and reviews signed previews before each list's first sync. A preview expires after ten minutes and is recalculated before writes. Later syncs can be manual or run every 5, 15, or 30 minutes after the grocery first sync is confirmed.
Home Assistant is reached through its REST API: todo.get_items uses POST /api/services/todo/get_items?return_response; todo.add_item and todo.update_item use the corresponding service paths. Responses are parsed from service_response[entity_id].items, and mappings use the returned item UID. The selected entity's supported_features controls whether create and update actions are offered. See the REST API, get-items action, and to-do feature flags.
Grocery sync shares only item name and needed/purchased state. New Home Assistant items become one-piece groceries. TasksNest quantity, unit, category, notes, product, inventory link, and recipe provenance stay local. The optional task sync shares title, completion, description, and scheduled date when the chosen Home Assistant entity advertises support. Task exports require Home Assistant create and due-date support; imports without a due date are skipped because TasksNest tasks require a scheduled date. Only active, top-level, non-recurring planner tasks sync. Recurrence, subtasks, priority, weather rules, and deferrals stay in TasksNest. A missing item is reported; it is never deleted on the other side. Equal titles without a UID mapping are flagged for review and not merged automatically. The default conflict winner is Home Assistant when both mapped sides changed. One direction modes apply the chosen side's syncable fields.
The sync uses per-user and per-entity UID mappings with local and remote fingerprints. A database lease prevents concurrent runs; at most twenty changes are applied per run. Automatic retries back off and stop after five consecutive failures; the user can re-enable them after reviewing the error. If an outbound add may have succeeded but its UID cannot be confirmed, its mapping remains pending. The next preview attempts UID reconciliation from a unique matching name but never blindly sends another add. A still-uncertain add can be reset only after the user confirms they checked the remote list. Recent run history and failure backoff are stored per connection.
Tokens are encrypted at rest with a Fernet key derived from Django's deployment SECRET_KEY. Rotating that key requires users to replace their Home Assistant tokens. Requests validate the destination, pin a checked DNS result for the socket, verify TLS, reject redirects, and use five-second timeouts. Private-network HTTP is permitted; public destinations require HTTPS. No token value is rendered or logged.
Automatic sync runs through manage.py sync_home_assistant; install main/deploy/systemd/tasknest-home-assistant-sync.service and .timer on the host to check for due syncs every minute. Automatic syncing is off by default. A live Home Assistant instance was not available during implementation, so API behavior is covered by mocked tests and a targeted browser smoke test with a fake server.