Files
iOS/Sources/Extensions/AppIntents/ShortcutAppIntentSupport.swift
Bruno Pantaleão Gonçalves be35df497a Deprecate older intents and migrate to App Intent (#4718)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->
This PR deprecate intents from siri intents definition and migrates them
to App Intent.
## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2026-06-09 16:35:30 +00:00

52 lines
1.4 KiB
Swift

import Foundation
import PromiseKit
import Shared
struct ShortcutAppIntentError: LocalizedError {
let errorDescription: String?
init(_ errorDescription: String) {
self.errorDescription = errorDescription
}
}
extension Promise {
func async() async throws -> T {
try await withCheckedThrowingContinuation { continuation in
pipe { result in
switch result {
case let .fulfilled(value):
continuation.resume(returning: value)
case let .rejected(error):
continuation.resume(throwing: error)
}
}
}
}
func timeout(seconds: TimeInterval) -> Promise<T> {
let timeout = after(seconds: seconds).then {
Promise<T>(error: ShortcutAppIntentError(L10n.AppIntents.Error.timedOut(Int(seconds))))
}
return race(self, timeout)
}
func async(timeout seconds: TimeInterval) async throws -> T {
try await timeout(seconds: seconds).async()
}
}
extension Sequence {
func asyncCompactMap<ElementOfResult>(
_ transform: (Element) async throws -> ElementOfResult?
) async throws -> [ElementOfResult] {
var result: [ElementOfResult] = []
for element in self {
if let transformed = try await transform(element) {
result.append(transformed)
}
}
return result
}
}