iOS/Sources/Extensions/Widgets/Controls/Automation/ControlAutomation.swift
Copilot 3f25cd80ab
Add automation domain and iOS control widget (#4120)
## 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>
2025-12-22 10:58:37 +00:00

38 lines
1.5 KiB
Swift

import Foundation
import Shared
import SwiftUI
import WidgetKit
@available(iOS 18, *)
struct ControlAutomation: ControlWidget {
var body: some ControlWidgetConfiguration {
AppIntentControlConfiguration(
kind: WidgetsKind.controlAutomation.rawValue,
provider: ControlAutomationsValueProvider()
) { template in
ControlWidgetButton(action: {
let intent = AutomationAppIntent()
intent.automation = .init(
id: template.intentAutomationEntity.id,
entityId: template.intentAutomationEntity.entityId,
serverId: template.intentAutomationEntity.serverId,
serverName: template.intentAutomationEntity.serverName,
displayString: template.intentAutomationEntity.displayString,
iconName: template.icon.id
)
intent.showConfirmationNotification = template.showConfirmationNotification
return intent
}()) {
// ControlWidget can only display SF Symbol
Label(
template.displayText ?? template.intentAutomationEntity.displayString,
systemImage: template.icon.id
)
}
.tint(.haPrimary)
}
.displayName(.init(stringLiteral: L10n.Widgets.Controls.Automation.displayName))
.description(.init(stringLiteral: L10n.Widgets.Controls.Automation.description))
}
}