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

48 lines
1.6 KiB
Swift

import AppIntents
import Shared
import UIKit
import UniformTypeIdentifiers
@available(iOS 17.0, *)
struct GetCameraSnapshotAppIntent: AppIntent {
static var title: LocalizedStringResource = .init(
"app_intents.get_camera_snapshot.title",
defaultValue: "Get camera snapshot"
)
static var description = IntentDescription(.init(
"app_intents.get_camera_snapshot.description",
defaultValue: "Get a single still frame from a camera"
))
static var parameterSummary: some ParameterSummary {
Summary {
\.$server
\.$camera
}
}
@Parameter(title: .init("app_intents.server.title", defaultValue: "Server"))
var server: IntentServerAppEntity
@Parameter(title: .init("app_intents.get_camera_snapshot.camera.title", defaultValue: "Camera"))
var camera: IntentCameraEntity
func perform() async throws -> some IntentResult & ReturnsValue<IntentFile> {
await Current.connectivity.syncNetworkInformation()
guard camera.serverId == server.id,
let server = server.getServer(),
let api = Current.api(for: server) else {
throw ShortcutAppIntentError(L10n.AppIntents.Error.noServer)
}
let image = try await api.getCameraSnapshot(cameraEntityID: camera.entityId).async()
guard let pngData = image.pngData() else {
throw ShortcutAppIntentError(L10n.AppIntents.GetCameraSnapshot.Error.pngConversion)
}
let filename = "\(camera.entityId)_snapshot.png"
return .result(value: .init(data: pngData, filename: filename, type: .png))
}
}