Files
iOS/Sources/Extensions/AppIntents/UpdateLocationAppIntent.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

42 lines
1.4 KiB
Swift

import AppIntents
import CoreLocation
import Shared
@available(iOS 16.4, *)
struct UpdateLocationAppIntent: AppIntent {
static var title: LocalizedStringResource = .init(
"app_intents.update_location.title",
defaultValue: "Update location"
)
static var description = IntentDescription(.init(
"app_intents.update_location.description",
defaultValue: "Send a location update to Home Assistant"
))
@Parameter(title: .init("app_intents.update_location.location.title", defaultValue: "Location"))
var location: CLPlacemark
func perform() async throws -> some IntentResult & ReturnsValue<String> {
await Current.connectivity.syncNetworkInformation()
let failedServers = try await Current.apis.asyncCompactMap { api -> String? in
do {
try await api.SubmitLocation(
updateType: .AppShortcut,
location: location.location,
zone: nil
).async(timeout: 10)
return nil
} catch {
return "\(api.server.info.name): \(error.localizedDescription)"
}
}
guard failedServers.isEmpty == false else {
return .result(value: L10n.AppIntents.UpdateLocation.success)
}
return .result(value: L10n.AppIntents.Error.failedServers(failedServers.joined(separator: ", ")))
}
}