Files
iOS/Sources/Extensions/Widgets/OpenEntity/ControlOpenEntity/ControlOpenEntityValueProvider.swift
Bruno Pantaleão Gonçalves 11d67f320f Add AppIntent to open entity more-info dialog (#3630)
<!-- 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. -->
2025-06-11 15:26:17 +02:00

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?
}