Kiosk mode: camera motion detection for screen wake#4497
Conversation
Adds 11 kiosk.camera.* keys covering motion detection, presence detection, face detection, sensitivity (low/medium/high), wake triggers, and footer copy. Regenerates SwiftGen output with updated Strings.swift accessors under L10n.Kiosk.Camera and L10n.Kiosk.Camera.Sensitivity.
…ings Adds MotionSensitivity enum (low/medium/high with threshold values) and 6 camera detection properties to KioskSettings: cameraMotionEnabled, cameraMotionSensitivity, wakeOnCameraMotion, cameraPresenceEnabled, cameraFaceDetectionEnabled, wakeOnCameraPresence. Replaces synthesized Codable with a custom init(from:) for backwards-compatible decoding so existing persisted settings without camera fields decode without error.
- Make processFrame/calculateDifference nonisolated in motion detector so CIFilter and CIContext.render run on processingQueue, not MainActor - Make processFrame nonisolated in presence detector so Vision requests run on processingQueue; settings read on MainActor then dispatched - Mark previousFrame, ciContext, and Vision requests as nonisolated(unsafe) since they are only accessed from their respective processing queues - Remove @published from errorMessage (internal debugging state, not UI) - Replace PR-specific comments in tests with neutral wording
Custom init(from:) suppresses the synthesized default initializer. Add explicit public init() so KioskSettings() continues to work.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4497 +/- ##
=======================================
Coverage ? 43.28%
=======================================
Files ? 275
Lines ? 16694
Branches ? 0
=======================================
Hits ? 7226
Misses ? 9468
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Sorry the delay to pickup this review, I will still need a bit more time since I am working on something else right now, meanwhile I noticed that after releasing the foundation for kiosk mode, lots of questions about how it works and comparisons to the famous "Fully Kiosk browser" popped up in the community, so it would be nice if we created a documentation page for this in out companion app docs, could you propose it? Reference: https://companion.home-assistant.io/docs/getting_started/ We need to make it clear things like... in iOS we cannot lock the user in a single app (from Home Assistant) and that the closest way possible to that is if the user uses iOS "guided access". So it needs to explain the difference of the "lock" that we mention inside Home Assistant app and the "lock" that the user may be expecting. |
The Kiosk Mode feature is really great. But for me, it’s not important to be locked into Kiosk Mode. It’s much more important that the Dashboard can be accessed more quickly and that you don’t have to unlock the iPad first. A true lock within an app also leads to other problems, such as not being able to use other apps at the same time, e.g., intercom apps. I opened an issue about this today: #4506 |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
@Macstar1601 thanks for sharing, we dont need to worry about that because the app is not able to lock itself as the only app, iOS doesn't allow that, the maximum we can do is to prevent the screen to turn off. |
There was a problem hiding this comment.
Pull request overview
Adds camera-based motion and presence detection to kiosk mode, wiring new detection settings into the kiosk settings model/UI and integrating camera-driven screen wake triggers into KioskModeManager.
Changes:
- Introduces camera motion (CoreImage pixel-diff) and presence/face detection (Vision) components plus a coordinator manager.
- Extends
KioskSettings+ settings UI with a new “Camera Detection” section and persistence/backwards-compat decoding. - Regenerates SwiftGen string accessors to include explicit fallback values for Frontend/Core strings, and adds SwiftUI helpers to SwiftGen assets.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
Tests/App/Kiosk/KioskCameraDetection.test.swift |
Adds Swift Testing coverage for MotionSensitivity and camera-related KioskSettings fields (defaults/roundtrip/back-compat). |
Sources/Shared/Resources/Swiftgen/FrontendStrings.swift |
SwiftGen output updated to provide fallback strings for Frontend keys; tr implementation changed accordingly. |
Sources/Shared/Resources/Swiftgen/CoreStrings.swift |
SwiftGen output updated to provide fallback strings for Core keys; tr implementation changed accordingly. |
Sources/Shared/Assets/Assets.swift |
Adds SwiftUI Image convenience initializers and a swiftUIImage accessor for ImageAsset. |
Sources/App/Resources/en.lproj/Localizable.strings |
Adds new kiosk camera detection strings (section labels, sensitivity labels, footer). |
Sources/App/Kiosk/Settings/KioskSettingsView.swift |
Adds a camera detection settings section (excluded on macCatalyst). |
Sources/App/Kiosk/KioskSettings.swift |
Adds camera detection settings fields, MotionSensitivity, and backwards-compatible decoding. |
Sources/App/Kiosk/KioskModeManager.swift |
Starts/stops camera detection with kiosk mode and restarts detection on relevant settings changes. |
Sources/App/Kiosk/Camera/KioskPresenceDetector.swift |
New Vision-based presence + face detection implementation. |
Sources/App/Kiosk/Camera/KioskCameraMotionDetector.swift |
New CoreImage motion detection implementation. |
Sources/App/Kiosk/Camera/KioskCameraDetectionManager.swift |
New coordinator that binds detectors and exposes callbacks + state. |
HomeAssistant.xcodeproj/project.pbxproj |
Adds new kiosk camera source files and test file to the project. |
Per bgoncal review on home-assistant#4497, ship motion detection first and defer presence/face detection to a follow-up PR for simpler review scope. Drops KioskPresenceDetector and the presence/face settings, UI toggles, manager wiring, and L10n keys.
Earlier SwiftGen run added a 'fallback:' arg to tr() calls that LocalizedManager doesn't accept (won't compile), reordered unrelated Strings entries, and added unused SwiftUI Image helpers to Assets.swift. Re-run with the project's existing template so the diff vs main is just the new kiosk.camera keys.
- KioskCameraDetectionManager.isActive now mirrors the underlying motion detector instead of being set from settings, so denied camera permission no longer leaves the manager stuck active. - Move previousFrame=nil into the processingQueue.async block to match its 'processingQueue-only' invariant. - Drop wakeOnCameraMotion from the settings-restart comparison; the closure already reads it at fire time, no need to recreate the capture session when only the wake flag toggles. - Toggling cameraMotionEnabled now requests camera permission and surfaces a denial alert that deep-links to iOS Settings, so the motion detector actually has something to start with.
|
Stripped face/presence so this PR is motion-only. The inline items are addressed in the latest commits. Companion-app docs proposal coming in a separate issue. |
|
Thanks for that, let me know whenever you have the docs PR so we can review that first before adding more features |
bgoncal
left a comment
There was a problem hiding this comment.
Let's keep it in draft while we don't have the docs
|
@nstefanelli Do you need some help with the docs? Or if you have created already and I missed it please tag me and I'll review asap |
|
Thanks @bgoncal — opened the docs PR over at home-assistant/companion.home-assistant#1323. It covers kiosk mode end-to-end (PR1 + this PR), flagged as BETA, with screenshot placeholders left in for you to flag whichever captures you want included. Happy to mark this PR ready for review whenever the docs side looks good to you, or earlier if that's easier on your end. |
Summary
Adds camera-based motion and presence detection to kiosk mode (PR2 of kiosk series, per discussion #2403).
Builds on #4422 (PR1: core kiosk infrastructure).
Architecture
New files
Camera/KioskCameraDetectionManager.swiftCamera/KioskCameraMotionDetector.swiftCamera/KioskPresenceDetector.swiftKioskCameraDetection.test.swiftTest plan
Related