Skip to content

Permit-join active state shared across Home toolbar and pairing wizard #43

@tashda

Description

@tashda

Summary

Permit-join state was tracked in two places:

  • HomeView held local @State for permitJoinStartTime, permitJoinDuration, permitJoinTargetName, set only when the user started permit_join from the Home toolbar.
  • BridgeInfo.permitJoin / permitJoinEnd reflected the bridge's authoritative state.

When the user started permit_join from the Add Devices wizard (or from a different Z2M client), the toolbar button correctly lit up "active" because bridgeInfo.permitJoin was true — but tapping it opened the active sheet with empty start time, zero duration, and no target. The countdown didn't run; the via-router scope wasn't shown.

Compounding this, Z2M sends permit_join event payloads with the via-device, but bridge/info doesn't include it. Every periodic info refresh was wiping the captured target back to nil and recomputing permitJoinEnd (either jumping it forward when the timeout was static, or zeroing it when omitted) — so the countdown also flickered or disappeared in the wizard.

Fix (commit on dev)

  • BridgeInfo gains permitJoinTarget: String?, captured by the bridgeEvent handler from the permit_join payload's device field. A new copyUpdatingPermitJoin(enabled:timeout:target:) helper recomputes permitJoinEnd correctly when state actually changes.
  • bridge/info updates while permit_join stays on now preserve the existing permitJoinEnd, permitJoinTimeout, and permitJoinTarget instead of overwriting them. We only adopt the new ones once the bridge tells us permit_join itself flipped.
  • HomeView derives permitJoinStartTime, permitJoinTotalDuration, and permitJoinTargetName from bridgeInfo instead of local state. Both HomeView.sendPermitJoin and the wizard do an optimistic bridgeInfo write so the UI updates instantly without waiting for the bridge round-trip.
  • Pairing wizard's "Network is open" row reads permitJoinTarget and shows "Network is open via Kitchen Relay" when scoped, plain "Network is open" otherwise.

Acceptance criteria

  • Start permit_join from the wizard, tap Cancel → Keep Open, navigate to Home, tap the toolbar button — countdown and via-target render correctly.
  • Start permit_join from Home toolbar — wizard, when opened, also shows the active state with countdown.
  • Cancelling permit_join from either surface dismisses the active sheet on the other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions