Skip to content

Consolidate sitemap page view models with shared OpenHABCore base#1245

Open
timbms wants to merge 6 commits into
developfrom
feature/sitemap-viewmodel-consolidation
Open

Consolidate sitemap page view models with shared OpenHABCore base#1245
timbms wants to merge 6 commits into
developfrom
feature/sitemap-viewmodel-consolidation

Conversation

@timbms

@timbms timbms commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduces SitemapPageViewModelBase (open class, @MainActor, ObservableObject) in OpenHABCore, subclassed by both SitemapPageViewModel (iOS) and UserData (watchOS). Shared state: currentPage, isLoading, error. Shared behaviour: runNewHandlingTask (task lifecycle with generation guard), runStreamLoop (drives SitemapPageLoader.stream), shouldRetryPolling (transient URL errors + HTTP 408/429/499/500/502/503/504), stopHandling.
  • Drops the SitemapPageLoader connectionInfo convenience overload; stream setup is now owned by the base class.
  • Adds SitemapLinkedPage (Hashable, Sendable) to OpenHABCore as a shared navigation value type, replacing the iOS-only LinkedPageNavigation. Carries link, title, and pageId explicitly. pageId is threaded through WidgetLinkedPageSnapshotLinkedPageRowInputWidgetRenderKey so the incremental builder detects page-ID-only changes, and SitemapNavigationView passes the authoritative ID directly to the view model rather than reconstructing it from the URL.
  • Adds localization entry for "Item '%@' not found" (auto-extracted by Xcode).

Tests

  • SitemapPageViewModelRetryPolicyTests: parameterized over all transient URL error codes, all retried HTTP status codes, terminal codes, named OpenAPIServiceError cases, and unknown errors.
  • SitemapPageViewModelTaskTests: same-key no-op, different-key replacement, force-restart, slot auto-clear after body returns, generation guard (stale cleanup doesn't clobber a newer task's slot).
  • SitemapRowInputBuilderTests: new case verifies incremental rebuild detects a linkedPageId-only change.

Test plan

  • Build iOS and watchOS targets
  • Navigate into a sub-sitemap page on iPhone; verify polling works and back navigation returns correctly
  • Navigate into a sub-sitemap page on Apple Watch; verify polling works and stopLongPolling on disappear cancels correctly
  • Simulate a transient server error (e.g. temporarily return 500); verify polling resumes automatically
  • All new unit tests pass

timbms and others added 6 commits June 11, 2026 22:33
…e base

Introduces SitemapPageViewModelBase (open class, @mainactor, ObservableObject)
in OpenHABCore, shared by SitemapPageViewModel (iOS) and UserData (watchOS):

- Common published state: currentPage, isLoading, error
- runNewHandlingTask: cancels and replaces running tasks; generation guard
  prevents a superseded task's cleanup from clearing a newer task's slot
- runStreamLoop: drives SitemapPageLoader.stream and calls handlePageUpdate;
  subclasses override handlePageUpdate for platform-specific behaviour
- shouldRetryPolling: shared transient-error policy covering URL errors and
  HTTP 408/429/499/500/502/503/504; static, placed before instance methods
- stopHandling: cancels the active task and resets loading state

Drops the SitemapPageLoader connectionInfo convenience overload; stream setup
is now owned by the base class.

Adds SitemapLinkedPage (Hashable, Sendable) to OpenHABCore as the shared
navigation value type, replacing the iOS-only LinkedPageNavigation. Carries
link, title, and pageId explicitly. pageId is threaded through
WidgetLinkedPageSnapshot → LinkedPageRowInput → SitemapLinkedPage so the
incremental builder detects pageId-only changes via WidgetRenderKey
(linkedPageId field added) and SitemapNavigationView passes the authoritative
ID directly to SitemapPageViewModel rather than reconstructing it from the URL.

Adds localization entry for "Item '%@' not found" (auto-extracted by Xcode).

Tests added in OpenHABCoreTests:
- SitemapPageViewModelRetryPolicyTests: parameterized over all transient URL
  error codes, all retried HTTP status codes, terminal codes, named error
  cases, and unknown errors
- SitemapPageViewModelTaskTests: same-key no-op, different-key replacement,
  force-restart, slot auto-clear after body returns, generation guard
- SitemapRowInputBuilderTests: incremental rebuild detects linkedPageId change

Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
… MediaRowView

Add missing linkedPageId field to MediaRowInput and wire it through both
construction sites so MediaRowView can construct SitemapLinkedPage correctly.

Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant