Skip to content

Commit

Permalink
Add force refresh widgets to debug tools (#2723)
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 committed Apr 18, 2024
1 parent ef6fef8 commit 6533d83
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,5 @@ Home Assistant is free and open source home automation software with a focus on
"widgets.open_page.description" = "Open a frontend page in Home Assistant.";
"widgets.open_page.not_configured" = "No Pages Available";
"widgets.open_page.title" = "Open Page";
"widgets.button.reload_timeline" = "Reload all widgets";
"yes_label" = "Yes";
12 changes: 12 additions & 0 deletions Sources/App/Settings/DebugSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import RealmSwift
import Shared
import SwiftUI
import WebKit
import WidgetKit
import XCGLogger

class DebugSettingsViewController: HAFormViewController {
Expand Down Expand Up @@ -139,6 +140,15 @@ class DebugSettingsViewController: HAFormViewController {
Section() <<< SettingsRootDataSource.Row.thread.row
}

private var reloadWidgetsButton: ButtonRow {
ButtonRow {
$0.title = L10n.Widgets.Button.reloadTimeline
$0.onCellSelection { _, _ in
WidgetCenter.shared.reloadAllTimelines()
}
}
}

private func logs() -> Eureka.Section {
let section = Section()

Expand Down Expand Up @@ -250,6 +260,8 @@ class DebugSettingsViewController: HAFormViewController {
$0.tag = "developerOptions"
}

section <<< reloadWidgetsButton

section <<< ButtonRow("onboardTest") {
$0.title = "Onboard (Initial)"
$0.presentationMode = .presentModally(controllerProvider: .callback(builder: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ struct WidgetActionsAppIntentTimelineProvider: AppIntentTimelineProvider {
}

func timeline(for configuration: Intent, in context: Context) async -> Timeline<Entry> {
.init(entries: [Self.entry(for: configuration, in: context)], policy: .never)
.init(
entries: [Self.entry(for: configuration, in: context)],
policy: .after(Current.date().addingTimeInterval(expiration.converted(to: .seconds).value))
)
}

func placeholder(in context: Context) -> WidgetActionsEntry {
Expand All @@ -27,6 +30,10 @@ struct WidgetActionsAppIntentTimelineProvider: AppIntentTimelineProvider {
return WidgetActionsEntry(actions: actions)
}

private var expiration: Measurement<UnitDuration> {
.init(value: 24, unit: .hours)
}

private static func entry(for configuration: Intent, in context: Context) -> Entry {
if let existing = configuration.actions?.compactMap({ $0.asAction() }), !existing.isEmpty {
return .init(actions: existing)
Expand Down
4 changes: 4 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,10 @@ public enum L10n {
/// Configure
public static var unknownConfiguration: String { return L10n.tr("Localizable", "widgets.assist.unknown_configuration") }
}
public enum Button {
/// Reload all widgets
public static var reloadTimeline: String { return L10n.tr("Localizable", "widgets.button.reload_timeline") }
}
public enum OpenPage {
/// Open a frontend page in Home Assistant.
public static var description: String { return L10n.tr("Localizable", "widgets.open_page.description") }
Expand Down

0 comments on commit 6533d83

Please sign in to comment.