-
-
Notifications
You must be signed in to change notification settings - Fork 134
Expand file tree
/
Copy pathHome.swift
More file actions
51 lines (44 loc) · 1.68 KB
/
Home.swift
File metadata and controls
51 lines (44 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2010-2026 Contributors to the openHAB project
//
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0
import AppIntents
import Foundation
import OpenHABCore
struct Home: AppEntity {
struct HomeQuery: EntityQuery {
@MainActor
func entities(for identifiers: [Home.ID]) async throws -> [Home] {
identifiers.compactMap { identifier in
guard let uuid = UUID(uuidString: identifier),
let homePrefs = Preferences.shared.storedHomes[uuid] else {
return nil
}
return Home(id: homePrefs.id.uuidString, displayString: homePrefs.homeName)
}
}
@MainActor
func suggestedEntities() async throws -> [Home] {
Preferences.shared.storedHomes.map { homePrefs in
Home(id: homePrefs.value.id.uuidString, displayString: homePrefs.value.homeName)
}
}
}
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "Home")
static let defaultQuery = HomeQuery()
var id: String // if your identifier is not a String, conform the entity to EntityIdentifierConvertible.
var displayString: String
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "\(displayString)")
}
init(id: String, displayString: String) {
self.id = id
self.displayString = displayString
}
}