Skip to content

Add push-based widget updates#4939

Draft
hariharanjagan wants to merge 7 commits into
home-assistant:mainfrom
hariharanjagan:main
Draft

Add push-based widget updates#4939
hariharanjagan wants to merge 7 commits into
home-assistant:mainfrom
hariharanjagan:main

Conversation

@hariharanjagan

@hariharanjagan hariharanjagan commented Jul 5, 2026

Copy link
Copy Markdown

Summary

Adds iOS 26 WidgetKit push support so widgets refresh via push instead of only
on the system's timeline schedule.

Using the new iOS 26 WidgetPushHandler API, a HAWidgetPushHandler is
attached to the data widgets. When the system issues a widget push token, the
handler registers that token together with the widget's tracked entity_ids
with the connected Home Assistant server, via the new register_push_subscription
webhook command. When any of those entities change, the server sends an APNs
widgets push and WidgetKit reloads the widget's timeline — no polling.

Covered widgets (those with a fixed, configured entity list):

  • Sensors — the entities chosen in the widget
  • To-do list — the selected list entity
  • Custom — the entity-type items in the widget

Deliberately excluded:

  • Gauge / Details — template-driven (Jinja rendered server-side), so there
    is no fixed entity list to subscribe to
  • Commonly used — entities are computed dynamically, so a static
    subscription would go stale

Also fixes a build break in WidgetSensors whose body bound the configuration
to let config without returning it, which prevented the Widgets extension from
compiling.

Screenshots

No new UI — this is a background refresh mechanism. Existing widgets simply
reload their content sooner (on entity change) instead of waiting for the next
scheduled timeline reload.

After Widget Push Notification
IMG_3132

Before Widget Push Notification
IMG_3131

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

This is the iOS portion of a three-part feature:

  1. Home Assistant Core — the platform-agnostic push-subscription mechanism
    (register_push_subscription webhook + entity-change tracking):
    Add entity-change push subscriptions to mobile_app core#174943
  2. This PR — the iOS WidgetPushHandler that registers the widget push
    token and tracked entities
  3. Push relay — formats the outgoing APNs widgets push from the
    subscription payload (separate change)

The Widgets extension needs the Push Notifications capability
(aps-environment) added
for the system to issue a widget push token. I left
that out of this PR because it's signing/capability configuration rather than
code — flagging it for the mobile team to add.

Validated end-to-end on a real iOS 26.5 device for the Sensors widget: the
handler registered the token + entities, an entity change triggered an APNs
widgets push, and the widget reloaded with the new value. To-do and Custom
compile and follow the identical registration path.

Related Pull Requests

Core - home-assistant/core#174943
FCM - home-assistant/mobile-apps-fcm-push#337

Note: the fork's distribute/CI job fails at code signing (it needs the repo's
signing secrets, which forks don't have) — not a code issue.

Refactor HAWidgetPushHandler to register one push subscription per widget
kind, keyed by a stable per-kind subscription_id, and extract tracked
entities for the sensors, todo-list and custom widgets. Apply the push
handler to the todo-list and custom widget configurations.

Gauge, details and commonly-used widgets are intentionally excluded: their
values come from server-rendered templates or dynamic usage prediction, so
there is no static entity list to subscribe.
Add HAWidgetPushHandler (iOS 26 WidgetPushHandler) and the
haWidgetPushHandlerIfAvailable() modifier so the sensor widget registers its
widget push token and tracked entity_ids with the server for push-driven
timeline reloads.

Also fix WidgetSensors.body, which bound the configuration to `let config`
without returning it and prevented the Widgets extension from compiling.

Includes only the project.pbxproj entries that add the two new files to the
Widgets target; signing/team changes are intentionally excluded.
Extend HAWidgetPushHandler to build one push subscription per widget kind
(sensors, todoList, custom) with a stable per-kind subscription_id, extracting
each widget's tracked entity_ids from its configuration intent. Gauge and
details are excluded (template-driven) as is commonlyUsedEntities (dynamic),
since they have no fixed entity list to subscribe.
Copilot AI review requested due to automatic review settings July 5, 2026 01:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds iOS 26 WidgetKit push support so selected widgets can refresh via APNs-triggered timeline reloads instead of relying solely on scheduled timelines.

Changes:

  • Introduces an iOS 26 WidgetPushHandler (HAWidgetPushHandler) that registers a widget push token + tracked entity_ids to Home Assistant via a new register_push_subscription webhook call.
  • Applies the push handler (via a WidgetConfiguration modifier) to widgets with a fixed entity list: Sensors, To-do List, and Custom.
  • Updates the Xcode project to include the new widget push handler sources.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Sources/Extensions/Widgets/TodoList/WidgetTodoList.swift Attaches the push handler modifier to the To-do List widget configuration.
Sources/Extensions/Widgets/Sensor/WidgetSensors.swift Attaches the push handler modifier to the Sensors widget configuration.
Sources/Extensions/Widgets/Sensor/HAWidgetPushHandler.swift New iOS 26 WidgetPushHandler implementation that registers push subscriptions per widget kind.
Sources/Extensions/Widgets/Custom/WidgetCustom.swift Attaches the push handler modifier to the Custom widget configuration.
Sources/Extensions/Widgets/Common/WidgetPushHandlerModifier.swift New modifier to conditionally apply pushHandler(...) on iOS 26+.
HomeAssistant.xcodeproj/project.pbxproj Adds the new Swift sources to the appropriate build targets/groups.

Comment thread Sources/Extensions/Widgets/Common/WidgetPushHandlerModifier.swift Outdated
Comment thread Sources/Extensions/Widgets/Sensor/HAWidgetPushHandler.swift Outdated
Comment thread Sources/Extensions/Widgets/Sensor/HAWidgetPushHandler.swift Outdated
Comment thread Sources/Extensions/Widgets/Sensor/HAWidgetPushHandler.swift
hariharanjagan and others added 2 commits July 5, 2026 03:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- Remove the Xcode-style file header blocks from the new widget push files,
  matching the repo convention for widget sources.
- Stop logging any part of the widget push token; log only counts/context.
- Log webhook registration failures instead of silently swallowing them with
  try?, so a failed registration is diagnosable.
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@f85a8de). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4939   +/-   ##
=======================================
  Coverage        ?   51.83%           
=======================================
  Files           ?      298           
  Lines           ?    19482           
  Branches        ?        0           
=======================================
  Hits            ?    10099           
  Misses          ?     9383           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Task {
do {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
Current.webhooks.sendEphemeral(server: server, request: request)

@bgoncal bgoncal Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails, when will it be retried?

@bgoncal bgoncal marked this pull request as draft July 6, 2026 07:13
@bgoncal

bgoncal commented Jul 6, 2026

Copy link
Copy Markdown
Member

Keeping it draft while we dont have the core PR ready, since all depends on that merged first

@bgoncal

bgoncal commented Jul 6, 2026

Copy link
Copy Markdown
Member

Please in all PR's you opened add a footer with link to all related PRs:

  • Core
  • iOS
  • FCM

So it's easier to navigate between them

@bgoncal bgoncal changed the title PR #174943 - Add push-based widget updates (iOS 26 WidgetKit push) Add push-based widget updates Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants