На первом этапе я буду называть свой ярлык, < /p>
На шаге 2: Он снова спросит температурную подсказку, пользователь отправит 25 ° C, поэтому он установит температуру устройства. Степень '.
Как это достичь?
Код: Выделить всё
@available(iOS 16.0, *)
public struct SetTemp: AppIntent, ProvidesDialog {
public var value: Never?
public init() {
IntentContext.currentIntentType = .setTemperature
}
public static var title: LocalizedStringResource = "Set Temperature"
@Parameter(title: "Temperature")
var device: SmartDevice
@Parameter(
title: "Temperature (°C)",
description: "Enter the temperature to set",
default: 24.0
)
var temperature: Double
public static var openAppWhenRun: Bool = false
public static var parameterSummary: some ParameterSummary {
Summary("Set \(\.$device) to \(\.$temperature)°C")
}
static var suggestedInvocationPhrases = [
"Set temperature",
"Set bone plus temperature to 22°C",
"Adjust thermostat"
]
public func perform() async throws -> some IntentResult & ProvidesDialog {
let tempStr = String(Int(temperature)) // Or round as needed
let resultStr = try await sendSwitchCommand(categoryType: .setTemperature, deviceName: device.name, deviceID: device.id, state: tempStr, locationId: device.locId, categoryId: device.categoryId)
return .result(dialog: IntentDialog(stringLiteral: resultStr))
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ice-comman