mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-18 06:26:35 -06: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. --> <img width="2568" height="1688" alt="CleanShot 2026-01-14 at 14 45 37@2x" src="https://github.com/user-attachments/assets/a1deb196-c51d-47e1-a2a3-15f6b82b697f" /> ## 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. -->
44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
import Foundation
|
|
import GRDB
|
|
import HAKit
|
|
|
|
public struct EntityRegistryListForDisplay: HADataDecodable {
|
|
public let entityCategories: [String: String]
|
|
public let entities: [Entity]
|
|
|
|
public init(data: HAData) throws {
|
|
self.entityCategories = try data.decode("entity_categories")
|
|
self.entities = try data.decode("entities")
|
|
}
|
|
|
|
public struct Entity: HADataDecodable, Codable, FetchableRecord, PersistableRecord {
|
|
public let entityId: String
|
|
public let entityCategory: Int?
|
|
public let decimalPlaces: Int?
|
|
|
|
public init(data: HAData) throws {
|
|
self.entityId = try data.decode("ei")
|
|
self.entityCategory = try? data.decode("ec")
|
|
self.decimalPlaces = try? data.decode("dp")
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct AppEntityRegistryListForDisplay: Codable, FetchableRecord, PersistableRecord {
|
|
/// serverId-entityId
|
|
public let id: String
|
|
public let serverId: String
|
|
public let entityId: String
|
|
public let registry: EntityRegistryListForDisplay.Entity
|
|
|
|
public static func config(serverId: String) throws -> [AppEntityRegistryListForDisplay] {
|
|
try Current.database().read { db in
|
|
try AppEntityRegistryListForDisplay
|
|
.filter(
|
|
Column(DatabaseTables.AppEntityRegistryListForDisplay.serverId.rawValue) == serverId
|
|
)
|
|
.fetchAll(db)
|
|
}
|
|
}
|
|
}
|