Skip to content

Commit

Permalink
Notification error actions
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-athome committed Feb 10, 2025
1 parent 43c64db commit 6d0e6d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,25 @@ open class HassRemoteRepository(private val project: Project, private val cs: Co
* Download error notification (usually network issues).
*/
private fun notifyDownloadError(module: Module, message: String) {
val moduleRef = ModulePointerManager.getInstance(module.project).create(module)

NotificationGroupManager.getInstance()
.getNotificationGroup("Home Assistant data refresh")
.createNotification(
MyBundle.message("hass.notification.refreshCache.title"),
message,
NotificationType.ERROR
)
.addAction(
NotificationAction.create(
MyBundle.message("hass.notification.error.action.tryAgain"),
"refresh-cache"
) { _, notification ->
moduleRef.module?.let { module ->
refreshCache(module, true)
}
notification.hideBalloon()
})
// TODO .addAction(<action for opening module settings>)
.notify(project)
}
Expand All @@ -475,12 +487,16 @@ open class HassRemoteRepository(private val project: Project, private val cs: Co
message,
NotificationType.ERROR
)
.addAction(NotificationAction.create("Refresh data", "refresh-cache") { anAction, notification ->
moduleRef.module?.let { module ->
refreshCache(module, true)
}
notification.hideBalloon()
})
.addAction(
NotificationAction.create(
MyBundle.message("hass.notification.error.action.tryAgain"),
"refresh-cache"
) { _, notification ->
moduleRef.module?.let { module ->
refreshCache(module, true)
}
notification.hideBalloon()
})
.notify(project)
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/MyBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ hass.notification.loadIconsError.title=Home Assistant icons

hass.notification.dataCacheError.title=Home Assistant data cache error
hass.notification.dataCacheError.genericError=Unable to load data cache.
hass.notification.error.action.tryAgain=Try again

0 comments on commit 6d0e6d7

Please sign in to comment.