mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-09 00:55:52 -06:00
Added calls to syncNetworkInformation() at the start of various perform() methods for AppIntents and widget controls to ensure up-to-date connectivity data before executing actions. Also refactored ConnectivityWrapper to support async network info synchronization. <!-- 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 --> ## 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. --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import Shared
|
|
|
|
@available(iOS 18, *)
|
|
struct ButtonIntent: AppIntent {
|
|
static var title: LocalizedStringResource = .init("app_intents.intent.button.title", defaultValue: "Press button")
|
|
|
|
@Parameter(title: .init("app_intents.button.title", defaultValue: "Button"))
|
|
var entity: IntentButtonEntity
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
await Current.connectivity.syncNetworkInformation()
|
|
guard let server = Current.servers.all.first(where: { $0.identifier.rawValue == entity.serverId }),
|
|
let connection = Current.api(for: server)?.connection else {
|
|
return .result()
|
|
}
|
|
|
|
// Button domains use the "press" service
|
|
let domain = Domain(entityId: entity.entityId) ?? .button
|
|
|
|
await withCheckedContinuation { continuation in
|
|
connection.send(.callService(
|
|
domain: .init(stringLiteral: domain.rawValue),
|
|
service: .init(stringLiteral: "press"),
|
|
data: [
|
|
"entity_id": entity.entityId,
|
|
]
|
|
)).promise.pipe { _ in
|
|
continuation.resume()
|
|
}
|
|
}
|
|
return .result()
|
|
}
|
|
}
|