Add iOS Live Activity webhook handlers to mobile_app#166072
Add iOS Live Activity webhook handlers to mobile_app#166072rwarner wants to merge 33 commits intohome-assistant:devfrom
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
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ivities Unifies the iOS and Android notification data field: live_update: true now triggers Live Activity routing on iOS, matching the field Android already uses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@rwarner the PR in the iOS repo is almost ready to merge, just minor touches, if you think this PR (in Core) is ready, please mark it as ready for review |
|
|
||
| device: dr.DeviceEntry = hass.data[DOMAIN][DATA_DEVICES][webhook_id] | ||
| hass.bus.async_fire( | ||
| EVENT_LIVE_ACTIVITY_DISMISSED, |
There was a problem hiding this comment.
It's confusing that it's called sometimes live_update and then live_activity
There was a problem hiding this comment.
From home-assistant/iOS#4444 (comment) it looks like we should rename everything to live_update
There was a problem hiding this comment.
The user-facing notification flag is live_update: true throughout. The live_activity naming is intentionally kept for the ActivityKit-specific internals (token store, push-to-start registration, webhook names) where it refers to the Apple feature rather than the notification field.
It does get a bit difficult, but don't want to overstep with Android references and/or YAML references to live_update
…y _get_live_activity_token signature - Drop EVENT_LIVE_ACTIVITY_TOKEN_UPDATED and EVENT_LIVE_ACTIVITY_DISMISSED — nothing consumes these events in any of the three repos (no automation triggers, no iOS listener, no relay usage), so they add noise without value - Remove supports_live_activities() from util.py — defined but never called - Pass app_data directly into _get_live_activity_token instead of the full registration dict (edenhaus review feedback) - Group Live Activity push constants with other PUSH attrs in const.py - Update tests to remove event-capture assertions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The generic 'tag' field name collides with the notification tag used elsewhere in mobile_app. Using 'live_activity_tag' makes the webhook contract unambiguous. notify.py continues to read 'tag' from the notification payload (user YAML) unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Core registered 'update_live_activity_token' and 'live_activity_dismissed' but the iOS app sends 'mobile_app_live_activity_token' and 'mobile_app_live_activity_dismissed', matching the mobile_app_ prefix convention used elsewhere in the integration. Rename core handlers to match. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Resolved and fixed comments. Difficult naming scheme between |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Proposed change
Adds server-side support for iOS Live Activities in the
mobile_appintegration. This is the HA core companion to the iOS companion app PR (home-assistant/iOS#4444) and the relay server PR (home-assistant/mobile-apps-fcm-push#278).Live Activities let Home Assistant automations push real-time state to the iOS Lock Screen. The iOS companion app handles the ActivityKit lifecycle; this PR adds the webhook handlers and notification routing that HA core needs to store, manage, and deliver per-activity push tokens.
How it works: When a notification contains
live_update: trueand atag, the notify service includes the stored APNs Live Activity token alongside the normal FCM registration token in the same request to the relay server. The relay server places it in the FCM message'sapns.liveActivityTokenfield, and FCM handles APNs delivery automatically — no separate endpoint, no APNs credentials, no environment routing needed.What this adds:
SCHEMA_APP_DATAvalidation forsupports_live_activities,supports_live_activities_frequent_updates,live_activity_push_to_start_token, andlive_activity_push_to_start_apns_environmentfields in device registration (push-to-start token and environment arevol.Inclusive— must be provided together)update_live_activity_tokenwebhook — stores per-activity APNs push tokens reported by the iOS app when a Live Activity is created locally via ActivityKitlive_activity_dismissedwebhook — cleans up stored tokens when a Live Activity ends on the device (also cleaned up on config entry unload)mobile_app_live_activity_token_updated/mobile_app_live_activity_dismissed) withEventOrigin.remoteso automations can react to activity lifecyclenotify.pyrouting — when a notification containslive_update: trueand atag, includes the Live Activity APNs token aslive_activity_tokenalongside the FCMpush_tokento the same relay URL. Falls back to the push-to-start token (iOS 17.2+) if no per-activity token exists for that tagsupports_live_activities()utility helper inutil.pyDATA_LIVE_ACTIVITY_TOKENSstore initialized in__init__.pyType of change
Additional information