mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-16 20:49:48 -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 --> Pending: - Allow color customisation - Choose to receive or not notification confirmation ## 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. -->
41 lines
1.4 KiB
Swift
41 lines
1.4 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import Shared
|
|
|
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
|
|
struct IntentActionAppEntity: AppEntity {
|
|
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "Action")
|
|
|
|
struct IntentActionAppEntityQuery: EntityQuery, EntityStringQuery {
|
|
func entities(for identifiers: [IntentActionAppEntity.ID]) async throws -> [IntentActionAppEntity] {
|
|
getActionEntities().filter { identifiers.contains($0.id) }
|
|
}
|
|
|
|
func entities(matching string: String) async throws -> [IntentActionAppEntity] {
|
|
getActionEntities().filter { $0.displayString.contains(string) }
|
|
}
|
|
|
|
func suggestedEntities() async throws -> [IntentActionAppEntity] {
|
|
getActionEntities()
|
|
}
|
|
|
|
private func getActionEntities() -> [IntentActionAppEntity] {
|
|
let actions = Current.realm().objects(Action.self).sorted(byKeyPath: #keyPath(Action.Position))
|
|
return Array(actions.map { IntentActionAppEntity(id: $0.ID, displayString: $0.Name) })
|
|
}
|
|
}
|
|
|
|
static let defaultQuery = IntentActionAppEntityQuery()
|
|
|
|
var id: String
|
|
var displayString: String
|
|
var displayRepresentation: DisplayRepresentation {
|
|
DisplayRepresentation(title: "\(displayString)")
|
|
}
|
|
|
|
init(id: String, displayString: String) {
|
|
self.id = id
|
|
self.displayString = displayString
|
|
}
|
|
}
|