mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-16 04:16:39 -05:00
<!-- 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. -->
52 lines
1.4 KiB
Swift
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
|
|
}
|
|
}
|