mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-18 21:51:51 -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 --> ## 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. -->
66 lines
2.0 KiB
Swift
66 lines
2.0 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import SFSafeSymbols
|
|
import Shared
|
|
import WidgetKit
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenEntityItem {
|
|
let entity: HAAppEntityAppIntentEntity
|
|
let icon: SFSymbolEntity
|
|
}
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenEntityValueProvider: AppIntentControlValueProvider {
|
|
func currentValue(configuration: ControlOpenEntityConfiguration) async throws -> ControlOpenEntityItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func placeholder(for configuration: ControlOpenEntityConfiguration) -> ControlOpenEntityItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func previewValue(configuration: ControlOpenEntityConfiguration) -> ControlOpenEntityItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
private func item(configuration: ControlOpenEntityConfiguration) -> ControlOpenEntityItem {
|
|
.init(
|
|
entity: configuration.entity ?? .init(
|
|
id: "",
|
|
entityId: "",
|
|
serverId: "",
|
|
serverName: "",
|
|
displayString: "",
|
|
iconName: ""
|
|
),
|
|
icon: configuration.icon ?? placeholder().icon
|
|
)
|
|
}
|
|
|
|
private func placeholder() -> ControlOpenEntityItem {
|
|
.init(
|
|
entity: .init(id: "", entityId: "", serverId: "", serverName: "", displayString: "", iconName: ""),
|
|
icon: .init(id: SFSymbol.rectangleAndPaperclip.rawValue)
|
|
)
|
|
}
|
|
}
|
|
|
|
@available(iOS 18.0, *)
|
|
struct ControlOpenEntityConfiguration: ControlConfigurationIntent {
|
|
static var title: LocalizedStringResource = .init(
|
|
"widgets.controls.open_entity.configuration.title",
|
|
defaultValue: "Open Entity"
|
|
)
|
|
|
|
@Parameter(
|
|
title: .init("widgets.controls.open_entity.configuration.parameter.entity", defaultValue: "Entity")
|
|
)
|
|
var entity: HAAppEntityAppIntentEntity?
|
|
|
|
@Parameter(
|
|
title: .init("app_intents.scenes.icon.title", defaultValue: "Icon")
|
|
)
|
|
var icon: SFSymbolEntity?
|
|
}
|