mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 05:08:23 -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 Allow action widget, open page widget, and watchOS style complications to be available on the iOS Lock Screen. ## Screenshots <img width="1163" alt="Screenshot 2024-06-30 at 9 28 19 AM" src="https://github.com/home-assistant/iOS/assets/62899372/be0fd76e-ae4a-494d-b564-9e467533087e"> <img width="722" alt="Screenshot 2024-06-30 at 11 17 13 AM" src="https://github.com/home-assistant/iOS/assets/62899372/d9ac98c8-acf4-4001-9a0c-461ba794c0ee"> <img width="677" alt="Screenshot 2024-06-30 at 9 29 26 AM" src="https://github.com/home-assistant/iOS/assets/62899372/6c2be522-dd78-4325-93e5-29e75ec20576"> ## 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: Bruno Pantaleão Gonçalves <bruno.ing879@gmail.com>
61 lines
1.8 KiB
Swift
61 lines
1.8 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import Shared
|
|
|
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
|
|
struct IntentServerAppEntity: AppEntity, Sendable {
|
|
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "MaterialDesignIcons")
|
|
|
|
struct IntentServerAppEntityQuery: EntityQuery, EntityStringQuery {
|
|
func entities(for identifiers: [IntentServerAppEntity.ID]) async throws -> [IntentServerAppEntity] {
|
|
getServerEntities().filter { identifiers.contains($0.id) }
|
|
}
|
|
|
|
func entities(matching string: String) async throws -> [IntentServerAppEntity] {
|
|
getServerEntities().filter { $0.getInfo()?.remoteName.contains(string) ?? false }
|
|
}
|
|
|
|
func suggestedEntities() async throws -> [IntentServerAppEntity] {
|
|
getServerEntities()
|
|
}
|
|
|
|
private func getServerEntities() -> [IntentServerAppEntity] {
|
|
Current.servers.all.map { IntentServerAppEntity(from: $0) }
|
|
}
|
|
|
|
func defaultResult() async -> IntentServerAppEntity? {
|
|
let server = Current.servers.all.first
|
|
if server == nil {
|
|
return nil
|
|
} else {
|
|
return IntentServerAppEntity(from: server!)
|
|
}
|
|
}
|
|
}
|
|
|
|
static let defaultQuery = IntentServerAppEntityQuery()
|
|
|
|
var id: String
|
|
var displayRepresentation: DisplayRepresentation {
|
|
DisplayRepresentation(
|
|
title: .init(stringLiteral: getInfo()?.name ?? "Unknown")
|
|
)
|
|
}
|
|
|
|
init(identifier: Identifier<Server>) {
|
|
self.id = identifier.rawValue
|
|
}
|
|
|
|
init(from server: Server) {
|
|
self.init(identifier: server.identifier)
|
|
}
|
|
|
|
func getServer() -> Server? {
|
|
Current.servers.server(for: .init(rawValue: id))
|
|
}
|
|
|
|
func getInfo() -> ServerInfo? {
|
|
getServer()?.info
|
|
}
|
|
}
|