Skip to content

Add systemSmall (Home Screen) support to the Gauge widget#4741

Draft
bahoo wants to merge 5 commits into
home-assistant:mainfrom
bahoo:gauge-systemsmall-widget
Draft

Add systemSmall (Home Screen) support to the Gauge widget#4741
bahoo wants to merge 5 commits into
home-assistant:mainfrom
bahoo:gauge-systemsmall-widget

Conversation

@bahoo

@bahoo bahoo commented Jun 14, 2026

Copy link
Copy Markdown

Summary

The Gauge widget has only ever offered .accessoryCircular (Lock Screen / watch-complication) because it originated as a watchOS-style complication ported to the Lock Screen in #2830. Home Screen support was never on the table there, so the limitation is an inheritance, not a design decision.

WidgetKit renders gauges in .systemSmall fine, and the data path (WidgetGaugeAppIntentTimelineProvider) is family-agnostic, so this is a view-only change:

  • Add .systemSmall to WidgetGaugeSupportedFamilies.families.
  • Branch WidgetGaugeView on \.widgetFamily: the Lock Screen path is unchanged; .systemSmall enlarges the existing gauge to fill a padded square. The container background requirement is already satisfied via the shared widgetBackground helper (containerBackground(_:for:.widget)).

No new strings, no provider/intent changes, no other references to the families list. Lock Screen behavior is byte-for-byte identical.

Screenshots

gaugeWidgetSystemSmallSnapshot light gaugeWidgetSystemSmallSnapshot dark

Link to pull request in Documentation repository

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

Any other notes

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

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds Home Screen support for the gauge widget by enabling the .systemSmall family and adjusting the widget’s layout so the accessory-style circular gauge scales appropriately inside a small tile.

Changes:

  • Add @Environment(\.widgetFamily) to adapt the view layout per widget family.
  • Scale the circular gauge for .systemSmall using GeometryReader + scaleEffect.
  • Expand the supported widget families to include .systemSmall.

Reviewed changes

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

File Description
Sources/Extensions/Widgets/Lockscreen/Gauge/WidgetGaugeView.swift Adds family-aware layout and scaling behavior for .systemSmall.
Sources/Extensions/Widgets/Lockscreen/Gauge/WidgetGauge.swift Registers .systemSmall as a supported widget family.

Comment thread Sources/Extensions/Widgets/Lockscreen/Gauge/WidgetGaugeView.swift Outdated
Comment thread Sources/Extensions/Widgets/Lockscreen/Gauge/WidgetGaugeView.swift Outdated
@bahoo bahoo force-pushed the gauge-systemsmall-widget branch from 008f8d5 to 938623a Compare June 14, 2026 17:14
@bgoncal

bgoncal commented Jun 15, 2026

Copy link
Copy Markdown
Member

How did you manage to set the accent color in your widget? It's always rendering black on my simulator.
Simulator Screenshot - Daily tester 2 - 2026-06-15 at 09 46 28

The Gauge widget has only ever offered `.accessoryCircular` (Lock Screen /
watch-complication) because it originated as a watchOS-style complication
ported to the Lock Screen in home-assistant#2830. Home Screen support was never on the
table there, so the limitation is an inheritance, not a design decision.

WidgetKit renders gauges in `.systemSmall` fine, and the data path
(WidgetGaugeAppIntentTimelineProvider) is family-agnostic, so this is a
view-only change:

- Add `.systemSmall` to `WidgetGaugeSupportedFamilies.families`.
- Branch `WidgetGaugeView` on `\.widgetFamily`: the Lock Screen path is
  unchanged; `.systemSmall` enlarges the existing gauge to fill a padded
  square. The container background requirement is already satisfied via the
  shared `widgetBackground` helper (`containerBackground(_:for:.widget)`).

No new strings, no provider/intent changes, no other references to the
families list. Lock Screen behavior is byte-for-byte identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bahoo bahoo force-pushed the gauge-systemsmall-widget branch from 938623a to b7d37d3 Compare June 15, 2026 18:32
The gauge widget views lived only in Extensions-Widgets, unlike the other widget
views (e.g. WidgetBasicContainerView, which is also in App), so they weren't
reachable from the snapshot-test target. Add WidgetGaugeView + its entry provider
to the App target to match, then add a light/dark systemSmall snapshot test
alongside the existing tile snapshots. Reference images were recorded on the
iOS 26.5 simulator; the existing tile snapshots pass in the same environment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bahoo

bahoo commented Jun 15, 2026

Copy link
Copy Markdown
Author

How did you manage to set the accent color in your widget? It's always rendering black on my simulator.

Ah, Claude invented that via ImageRenderer 😃 With latest pushes, it now uses .tint(Color.haPrimary). I also added a snapshot test for it — that needed the gauge views moved into the App target (they were Extensions-Widgets only, unlike WidgetBasicContainerView), so they're reachable from Tests-App.

@bgoncal

bgoncal commented Jun 15, 2026

Copy link
Copy Markdown
Member

Shouldn't the highlighted part be gray? since the value does not go as far?
CleanShot 2026-06-15 at 21 59 20@2x

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4741   +/-   ##
=======================================
  Coverage        ?   44.96%           
=======================================
  Files           ?      275           
  Lines           ?    16701           
  Branches        ?        0           
=======================================
  Hits            ?     7510           
  Misses          ?     9191           
  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.

The .normal and .singleLabel gauge types now draw the tint as a partial
arc (0…value) over a dim track — matching Apple's Batteries gauge — instead
of tinting the whole ring with a separate dot indicator. This applies on
both the Home Screen and the Lock Screen, where the system's vibrant
rendering preserves the bright-fill / dim-track band. The .capacity type is
unchanged (it already fills natively).

Min/max labels are tucked inside the ring so the Lock Screen's circular mask
doesn't clip them. Adds snapshot coverage for the single-label, capacity, and
accessoryCircular variants, plus #Preview blocks for eyeballing the real
Lock Screen rendering.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bahoo

bahoo commented Jun 15, 2026

Copy link
Copy Markdown
Author

Good feedback. It will now show the progress as its own colored track in the Home / Widget view:

image

In the process I discovered the lock screen should follow suit ( lighter vs. darker to show fill ) so I've incorporated that change:

image

In both cases, I've also removed the separate dot indicator. Not strongly felt on any of these if you have other preferences / feedback; I'm just trying to mimic Apple's design with battery levels for AirPods etc, see below:

IMG_9682 IMG_9681

@bgoncal bgoncal left a comment

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.

While the new design works best for home screen, this PR also change the UI for the lock screen widget, which is not the main goal and should be reverted.

I tested it in Home Screen using plain values and did not see the correct state of the widget. Please double check the implementation and send a screen recording configuring the widget and showing how it looks after configured, including home and lock screen.

Finally the preview is also blank, I see you wrote code to populate it so you may want to check as well.

Image

@home-assistant

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant Bot marked this pull request as draft June 16, 2026 08:57
@bahoo

bahoo commented Jun 16, 2026

Copy link
Copy Markdown
Author

Good call, I'll work on splitting the lock screen into a separate PR, since that's new scope, as well as the other changes you laid out.

Also I think I have spotted an issue in your screenshot — in the bottom row, left most screen, the Value Template field looks set to 2. That field is what drives the fill amount, and is expected to be normalized 0–1, so any value ≥ 1 clamps to a totally full gauge (= 100%). Try setting it to e.g. 0.6 (= 60%) and you should get the correct partial fill.

More to follow ...

@bgoncal

bgoncal commented Jun 16, 2026

Copy link
Copy Markdown
Member

Oh good catch, totally forgot about that, let me know when I can test again.

Per review, the partial-fill arc is applied only on the Home Screen
(.systemSmall). The Lock Screen (.accessoryCircular) returns to the native
accessory gauge — changing the Lock Screen is separate scope and will be
proposed in its own PR. Also drops the #Preview scaffolding and the
accessoryCircular snapshot tests/references that were specific to that work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bahoo

bahoo commented Jun 16, 2026

Copy link
Copy Markdown
Author

OK lock screen style changes, and preview both removed. And here is my video testing it out ( somewhat clumsily through Remote Desktop and Simulator, apologies in advance ! ):

https://www.youtube.com/watch?v=01YcLf80y2M

@bgoncal

bgoncal commented Jun 17, 2026

Copy link
Copy Markdown
Member

You mentioned you removed the preview value but what I actually meant was to make the preview work, so users dont see an empty widget when looking at the widget picker, makes sense?

Also, the home screen widget is not vertically centered, can you check that?

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