iOS/Sources/Shared/Models/EntityRegistryListForDisplay.swift
Bruno Pantaleão Gonçalves 6f577ebb6f
Add rooms layout option to native dashboard (#4220)
<!-- 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. -->
2026-01-14 15:58:43 +01:00

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