Add iOS Live Activity webhook handlers to mobile_app#166072
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
|
There was a problem hiding this comment.
Pull request overview
Adds Home Assistant Core support in the mobile_app integration for iOS Live Activities by introducing webhook handlers that store and clear per-activity APNs push tokens and emit lifecycle events for automations.
Changes:
- Extend
SCHEMA_APP_DATAand constants to support Live Activities capability flags and push-to-start registration fields. - Add
update_live_activity_tokenandlive_activity_dismissedwebhooks that manage an in-memory token store and fire remote-origin bus events. - Add a
supports_live_activities()helper and webhook tests covering token storage, defaults, and cleanup.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
homeassistant/components/mobile_app/const.py |
Adds Live Activity-related constants/events and extends registration SCHEMA_APP_DATA. |
homeassistant/components/mobile_app/__init__.py |
Initializes a new in-memory DATA_LIVE_ACTIVITY_TOKENS store under hass.data[DOMAIN]. |
homeassistant/components/mobile_app/webhook.py |
Implements the new Live Activity webhook handlers and fires lifecycle events. |
homeassistant/components/mobile_app/util.py |
Adds supports_live_activities() helper based on stored app_data. |
tests/components/mobile_app/test_webhook.py |
Adds tests for storing tokens, default env behavior, and dismiss cleanup/event firing. |
Comments suppressed due to low confidence (1)
tests/components/mobile_app/test_webhook.py:1398
- This test only asserts the HTTP status. To fully validate the contract of
live_activity_dismissed(which returnsempty_okay_response()), also assert the JSON body is{}(and optionally that no tokens were removed when none existed) to prevent regressions in response shape/side effects.
resp = await webhook_client.post(
f"/api/webhook/{webhook_id}",
json={
"type": "live_activity_dismissed",
"data": {
"tag": "nonexistent_activity",
},
},
)
assert resp.status == HTTPStatus.OK
- Remove unused AsyncGenerator import from notify.py - Sort ATTR_PUSH_TAG import alphabetically (after ATTR_PUSH_RATE_LIMITS_SUCCESSFUL) - Wrap long line in webhook_update_live_activity_token Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Store per-activity tokens as {"push_token": <token>} dict in
DATA_LIVE_ACTIVITY_TOKENS so the structure matches test expectations
and leaves room for additional fields without a schema change
- Update _get_live_activity_token to read the push_token key from the dict
- Update test_notify.py setups to use dict format
- Fix stale "mobile_app_live_activity_token" type name in test_init.py
(should be "live_activity_token" after the prefix-drop rename)
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
9cf6a0e to
eb478d4
Compare
|
Please don't rebase after a review have started as this means a reviewer needs to review again the whole PR instead of the changes. Keep this in mind and also instruct claude to do it |
|
Previously requested changes are not implemented. Drafting the PR. Not sure if the AI has reintroduced them or if they still pending to implement but due the rebase each commit is marked as new and I will not check each commit. Please make sure all previous requested changes are implemented correctly before marking the PR as ready for review. and again we require the human in the loop and it feels from the comments that the are written completely by the AI |
edenhaus
left a comment
There was a problem hiding this comment.
PR description not in sync with the changes
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Okay addressing some of the things here. This has unfortunately gotten to be a mess
Yes, I did use AI for some responses that I felt like it could explain more sufficiently than I could. But I am personally involved in all of this. I apologize, as I was unaware this was against policy with OHF
Updated the description to match with current fork branch changes
Sorry, again I was unaware this was a bad thing and now understand. It was 100+commits behind and I was simply doing this to try to fix CI solely. Items that were tended to, as some things were lost during the rebase and I thought they were still in there:
I have "unresolved" the comments that were lost during the rebase so they can be re-verified. Would it be better for you @edenhaus if I just started a new PR at this point? |
No let's continue in this PR. just don't do any force pushes. Will do a full review after the store is in place so it's fine. |
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…anup Tokens are now stored via a dedicated Store (mobile_app.live_activity_tokens) so they survive HA restarts. Each token is saved with a stored_at timestamp; tokens older than 8 hours are filtered on load and cleaned up lazily on lookup. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Re-instated the accidental removal of that comment above Integrated the storage capability for tokens: 25340ac Let me know how its looking overall and anything else to do |
|
Please fix the merge conflict. If you think the PR is ready for another review please mark it as ready for review. Will wait for the next review until it's marked ready for review |
Sounds good. I was hesitant to mess it up again with the whole rebase and update from last time |
Removes the separate live_activity_tokens store. Tokens are now saved
in the main mobile_app store (STORAGE_VERSION bumped to 2). Existing
v1 data is migrated inline by defaulting the new key to {}. Stores
timestamps as floats so no custom datetime parsing is needed.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Added to existing store: b0cb713 Removed custom datetime parsing |
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Proposed change
Adds server-side support for iOS Live Activities in the `mobile_app` integration. This is the HA core companion to the iOS companion app PRs and the relay server PR.
Live Activities let Home Assistant automations push real-time state to the iOS Lock Screen and Dynamic Island. The iOS app handles the ActivityKit lifecycle; this PR adds the webhook handlers and notification routing that HA core needs.
How it works: When a notification contains `live_update: true` and a `tag`, the notify service looks up the stored APNs Live Activity token for that tag and includes it alongside the normal FCM registration token in the relay request. The relay places it in the FCM message's `apns.liveActivityToken` field — no separate APNs endpoint or credentials needed. If no per-activity token exists, it falls back to the device's push-to-start token (iOS 17.2+) to start a new activity remotely.
What this adds:
Type of change
Additional information
Part of epic: home-assistant/epics#61
Fixes: home-assistant/iOS#4623