fix(k1): restore canonical local connection lifecycle

This commit is contained in:
DCCONSTRUCTIONS
2026-08-06 13:52:46 +03:00
parent 52da9b75b7
commit aff331082f
19 changed files with 2169 additions and 274 deletions
@@ -2,6 +2,7 @@ import type { RuntimePhase, SourceMode as RuntimeSourceMode } from "@mission-cor
import type {
AcquisitionState,
BleDevice,
XgridsApplicationControlPhase,
XgridsAcquisition,
XgridsK1State,
@@ -200,6 +201,50 @@ export function operationNeedsReconciliation(
return operation.error?.safe_to_retry !== true;
}
export function provisioningCandidateById(
devices: readonly BleDevice[],
selectedDeviceId: string,
): BleDevice | null {
if (!selectedDeviceId) return null;
return devices.find((device) => device.device_id === selectedDeviceId) ?? null;
}
export function canSubmitProvisioningMutation({
devices,
selectedDeviceId,
powerConfirmed,
credentialsReady,
isBusy,
}: {
devices: readonly BleDevice[];
selectedDeviceId: string;
powerConfirmed: boolean;
credentialsReady: boolean;
isBusy: boolean;
}): boolean {
const candidate = provisioningCandidateById(devices, selectedDeviceId);
return Boolean(
powerConfirmed &&
credentialsReady &&
!isBusy &&
candidate &&
candidate.connectable !== false,
);
}
export function isReachableConnectionLease(
state: XgridsK1State | null | undefined,
connectionMode: NonNullable<XgridsK1State["connection_mode"]>,
): boolean {
const verification = state?.connection_verification;
return Boolean(
state?.k1_ip &&
state.connection_mode === connectionMode &&
verification?.lease_state === "reachable" &&
verification.network_reachability === "reachable",
);
}
function defaultUuid(): string {
const cryptoApi = globalThis.crypto;
if (!cryptoApi) {