All files / session connectionLifecycle.ts

85.71% Statements 6/7
83.33% Branches 5/6
100% Functions 3/3
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16        2x 2x 2x             2x    
import type { SmartCubeTransportConnection } from '../bindings/smartCubeTransport.js';
 
/** Request the common state snapshots supported by a connected cube. */
export async function requestInitialState(connection: SmartCubeTransportConnection): Promise<void> {
  if (connection.capabilities.hardware) await connection.sendCommand({ type: 'REQUEST_HARDWARE' });
  Iif (connection.capabilities.facelets) await connection.sendCommand({ type: 'REQUEST_FACELETS' });
  if (connection.capabilities.battery) await connection.sendCommand({ type: 'REQUEST_BATTERY' });
}
 
/** Disconnect without allowing transport cleanup errors to mask session teardown. */
export async function disconnectConnection(
  connection: SmartCubeTransportConnection | null,
): Promise<void> {
  await connection?.disconnect().catch(() => {});
}