Skip to content

Commit

Permalink
Improve logs for entities model updater (#3283)
Browse files Browse the repository at this point in the history
<!-- 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. -->

## 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. -->
  • Loading branch information
bgoncal authored Dec 17, 2024
1 parent a9e6896 commit c5b9cae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Shared/API/Models/AppEntitiesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ final class AppEntitiesModel: AppEntitiesModelProtocol {
} catch {
Current.Log.error("Failed to get cache for App Entities, error: \(error.localizedDescription)")
Current.clientEventStore.addEvent(ClientEvent(
text: "Updated database App Entities for \(server.info.name)",
text: "Update database App Entities FAILED for \(server.info.name)",
type: .database,
payload: ["entities_count": appEntities.count]
payload: ["error": error.localizedDescription]
)).cauterize()
}
}
Expand Down
23 changes: 22 additions & 1 deletion Sources/Shared/Environment/PeriodicAppEntitiesModelUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ final class PeriodicAppEntitiesModelUpdater: PeriodicAppEntitiesModelUpdaterProt
Current.appEntitiesModel().updateModel(Set(entities), server: server)
case let .failure(error):
Current.Log.error("Failed to fetch states: \(error)")
Current.clientEventStore.addEvent(.init(
text: "Failed to fetch states on server \(server.info.name)",
type: .networkRequest,
payload: [
"error": error.localizedDescription,
]
)).cauterize()
}
}
)
Expand All @@ -50,7 +57,14 @@ final class PeriodicAppEntitiesModelUpdater: PeriodicAppEntitiesModelUpdaterProt
case let .success(response):
self?.saveEntityRegistryListForDisplay(response, serverId: server.identifier.rawValue)
case let .failure(error):
Current.Log.error("Failed to fetch states: \(error)")
Current.Log.error("Failed to fetch EntityRegistryListForDisplay: \(error)")
Current.clientEventStore.addEvent(.init(
text: "Failed to fetch EntityRegistryListForDisplay on server \(server.info.name)",
type: .networkRequest,
payload: [
"error": error.localizedDescription,
]
)).cauterize()
}
}
)
Expand Down Expand Up @@ -80,6 +94,13 @@ final class PeriodicAppEntitiesModelUpdater: PeriodicAppEntitiesModelUpdaterProt
} catch {
Current.Log
.error("Failed to save EntityRegistryListForDisplay in database, error: \(error.localizedDescription)")
Current.clientEventStore.addEvent(.init(
text: "Failed to save EntityRegistryListForDisplay in database, error on serverId \(serverId)",
type: .database,
payload: [
"error": error.localizedDescription,
]
)).cauterize()
}
}

Expand Down

0 comments on commit c5b9cae

Please sign in to comment.