Files
iOS/Sources/Shared/Models/EntityRegistryListForDisplay.swift
Bruno Pantaleão Gonçalves e71f746b87 Make app database updates non-blocking and skip redundant writes (#4731)
<!-- 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 -->
Improves `AppDatabaseUpdater` (the per-server fetch + persist pipeline
that runs on
view-appear, pull-to-refresh, and the Settings "refresh" action) so it
does less work
and stops touching the main thread.

## 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. -->

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 14:28:01 +02: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, Equatable {
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, Equatable {
/// 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)
}
}
}