mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-09 10:11:23 -06:00
## Summary Adds support for Home Assistant automations in the iOS app. Automations can now be triggered from iOS Control Center widgets (iOS 18+), similar to existing script and scene controls. **Domain & Model** - Added `automation` domain with robot icon and `trigger` service - Included automation in `AppEntitiesModel` tracked domains for database caching - Added to CarPlay supported domains **Control Widget** (iOS 18+) - `ControlAutomation` - Main control widget - `AutomationAppIntent` - Triggers `automation.trigger` service - `IntentAutomationEntity` - Entity queries and selection - `ControlAutomationsValueProvider` - Configuration with custom icons/text **Pattern** Follows existing `ControlScript` and `ControlScene` implementation patterns for consistency. **Tests** - Updated `testWidgetsKindCasesValues` to include assertion for `controlAutomation` case - Updated widget kind count validation from 25 to 26 ## Screenshots N/A - Control widgets are system UI and cannot be screenshotted during development. Widget appears in Control Center configuration with automation icon and allows selection from available automations. ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes Localization strings added for English only. Additional languages will need translation via the standard localization workflow. <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > 1 - Add "automation" in AppEntitiesModel domains > 2 - Create an iOS control for running automation like it exist for ControlScript </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/home-assistant/iOS/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
89 lines
3.0 KiB
Swift
89 lines
3.0 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import Shared
|
|
import WidgetKit
|
|
|
|
@available(iOSApplicationExtension 18, *)
|
|
struct ControlAutomationItem {
|
|
let intentAutomationEntity: IntentAutomationEntity
|
|
let icon: SFSymbolEntity
|
|
let showConfirmationNotification: Bool
|
|
let displayText: String?
|
|
}
|
|
|
|
@available(iOSApplicationExtension 18, *)
|
|
struct ControlAutomationsValueProvider: AppIntentControlValueProvider {
|
|
func currentValue(configuration: ControlAutomationConfiguration) async throws -> ControlAutomationItem {
|
|
.init(
|
|
intentAutomationEntity: configuration.automation ?? placeholder(),
|
|
icon: configuration.icon ?? placeholderIcon(),
|
|
showConfirmationNotification: configuration.showConfirmationDialog,
|
|
displayText: configuration.displayText
|
|
)
|
|
}
|
|
|
|
func placeholder(for configuration: ControlAutomationConfiguration) -> ControlAutomationItem {
|
|
.init(
|
|
intentAutomationEntity: configuration.automation ?? placeholder(),
|
|
icon: configuration.icon ?? placeholderIcon(),
|
|
showConfirmationNotification: configuration.showConfirmationDialog,
|
|
displayText: configuration.displayText
|
|
)
|
|
}
|
|
|
|
func previewValue(configuration: ControlAutomationConfiguration) -> ControlAutomationItem {
|
|
.init(
|
|
intentAutomationEntity: configuration.automation ?? placeholder(),
|
|
icon: configuration.icon ?? placeholderIcon(),
|
|
showConfirmationNotification: configuration.showConfirmationDialog,
|
|
displayText: configuration.displayText
|
|
)
|
|
}
|
|
|
|
private func placeholder() -> IntentAutomationEntity {
|
|
.init(
|
|
id: UUID().uuidString,
|
|
entityId: "",
|
|
serverId: "",
|
|
serverName: "",
|
|
displayString: L10n.Widgets.Controls.Automations.placeholderTitle,
|
|
iconName: ""
|
|
)
|
|
}
|
|
|
|
private func placeholderIcon() -> SFSymbolEntity {
|
|
.init(id: "gearshape.fill")
|
|
}
|
|
}
|
|
|
|
@available(iOSApplicationExtension 18.0, *)
|
|
struct ControlAutomationConfiguration: ControlConfigurationIntent {
|
|
static var title: LocalizedStringResource = .init("widgets.automations.description", defaultValue: "Run Automation")
|
|
|
|
@Parameter(
|
|
title: .init("app_intents.automations.automation.title", defaultValue: "Automation")
|
|
)
|
|
var automation: IntentAutomationEntity?
|
|
@Parameter(
|
|
title: .init("app_intents.automations.icon.title", defaultValue: "Icon")
|
|
)
|
|
var icon: SFSymbolEntity?
|
|
|
|
@Parameter(
|
|
title: LocalizedStringResource(
|
|
"app_intents.notify_when_run.title",
|
|
defaultValue: "Notify when run"
|
|
),
|
|
description: LocalizedStringResource(
|
|
"app_intents.notify_when_run.description",
|
|
defaultValue: "Shows notification after executed"
|
|
),
|
|
default: true
|
|
)
|
|
var showConfirmationDialog: Bool
|
|
@Parameter(
|
|
title: .init("app_intents.display_text.title", defaultValue: "Display Text")
|
|
)
|
|
var displayText: String?
|
|
}
|