{"version":3,"file":"device-client-BmyNf5Sh.mjs","names":[],"sources":["../src/device/device-client.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\nimport {\n  callServiceFunction,\n  closeService,\n  isServiceAvailable,\n  openService,\n  resolveHost,\n  type ServiceClientOptions,\n  type ServiceHandle,\n} from '../common/service-rpc.ts';\nimport type {\n  DeviceBoardInfo,\n  DeviceCameraInfo,\n  DeviceCapability,\n  DeviceNetworkConnectivityInfo,\n  DevicePowerBatteryChargeConfig,\n  DevicePowerBatteryInfo,\n  DevicePowerBatteryState,\n} from './device-types.ts';\n\n/** Registered name (`helper::Device::get_name()`). */\nexport const DEVICE_SERVICE_NAME = 'Device';\n\n/** RPC function names (`helper::Device::FunctionId`). */\nexport const DEVICE_FUNCTIONS = {\n  GetCapabilities: 'GetCapabilities',\n  GetBoardInfo: 'GetBoardInfo',\n  GetCameraDeviceInfos: 'GetCameraDeviceInfos',\n  GetNetworkConnectivityInfo: 'GetNetworkConnectivityInfo',\n  GetPowerBatteryInfo: 'GetPowerBatteryInfo',\n  GetPowerBatteryState: 'GetPowerBatteryState',\n  GetPowerBatteryChargeConfig: 'GetPowerBatteryChargeConfig',\n  SetPowerBatteryChargeConfig: 'SetPowerBatteryChargeConfig',\n  SetPowerBatteryChargingEnabled: 'SetPowerBatteryChargingEnabled',\n} as const;\n\nexport type DeviceClientOptions = ServiceClientOptions;\n\nexport { type ServiceHandle as DeviceHandle };\n\nexport function isDeviceAvailable(options?: DeviceClientOptions): boolean {\n  return isServiceAvailable(DEVICE_SERVICE_NAME, options);\n}\n\nexport function openDevice(options?: DeviceClientOptions): ServiceHandle {\n  return openService(DEVICE_SERVICE_NAME, options);\n}\n\nexport function closeDevice(handle: ServiceHandle, options?: DeviceClientOptions): void {\n  closeService(handle, options);\n}\n\nfunction callDevice<T>(\n  handle: ServiceHandle,\n  functionName: string,\n  params: Record<string, unknown>,\n  options?: DeviceClientOptions,\n): T {\n  return callServiceFunction<T>(resolveHost(options), handle, functionName, params);\n}\n\nexport function getCapabilities(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DeviceCapability[] {\n  return callDevice<DeviceCapability[]>(handle, DEVICE_FUNCTIONS.GetCapabilities, {}, options);\n}\n\nexport function getBoardInfo(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DeviceBoardInfo {\n  return callDevice<DeviceBoardInfo>(handle, DEVICE_FUNCTIONS.GetBoardInfo, {}, options);\n}\n\nexport function getCameraDeviceInfos(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DeviceCameraInfo[] {\n  return callDevice<DeviceCameraInfo[]>(handle, DEVICE_FUNCTIONS.GetCameraDeviceInfos, {}, options);\n}\n\nexport function getNetworkConnectivityInfo(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DeviceNetworkConnectivityInfo[] {\n  return callDevice<DeviceNetworkConnectivityInfo[]>(\n    handle,\n    DEVICE_FUNCTIONS.GetNetworkConnectivityInfo,\n    {},\n    options,\n  );\n}\n\nexport function getPowerBatteryInfo(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DevicePowerBatteryInfo {\n  return callDevice<DevicePowerBatteryInfo>(\n    handle,\n    DEVICE_FUNCTIONS.GetPowerBatteryInfo,\n    {},\n    options,\n  );\n}\n\nexport function getPowerBatteryState(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DevicePowerBatteryState {\n  return callDevice<DevicePowerBatteryState>(\n    handle,\n    DEVICE_FUNCTIONS.GetPowerBatteryState,\n    {},\n    options,\n  );\n}\n\nexport function getPowerBatteryChargeConfig(\n  handle: ServiceHandle,\n  options?: DeviceClientOptions,\n): DevicePowerBatteryChargeConfig {\n  return callDevice<DevicePowerBatteryChargeConfig>(\n    handle,\n    DEVICE_FUNCTIONS.GetPowerBatteryChargeConfig,\n    {},\n    options,\n  );\n}\n\nexport function setPowerBatteryChargeConfig(\n  handle: ServiceHandle,\n  config: DevicePowerBatteryChargeConfig,\n  options?: DeviceClientOptions,\n): void {\n  callDevice<void>(\n    handle,\n    DEVICE_FUNCTIONS.SetPowerBatteryChargeConfig,\n    { Config: config },\n    options,\n  );\n}\n\nexport function setPowerBatteryChargingEnabled(\n  handle: ServiceHandle,\n  enabled: boolean,\n  options?: DeviceClientOptions,\n): void {\n  callDevice<void>(\n    handle,\n    DEVICE_FUNCTIONS.SetPowerBatteryChargingEnabled,\n    { Enabled: enabled },\n    options,\n  );\n}\n"],"mappings":";;;AAuBA,MAAa,sBAAsB;;AAGnC,MAAa,mBAAmB;CAC9B,iBAAiB;CACjB,cAAc;CACd,sBAAsB;CACtB,4BAA4B;CAC5B,qBAAqB;CACrB,sBAAsB;CACtB,6BAA6B;CAC7B,6BAA6B;CAC7B,gCAAgC;AAClC;AAMA,SAAgB,kBAAkB,SAAwC;CACxE,OAAO,mBAAmB,qBAAqB,OAAO;AACxD;AAEA,SAAgB,WAAW,SAA8C;CACvE,OAAO,YAAY,qBAAqB,OAAO;AACjD;AAEA,SAAgB,YAAY,QAAuB,SAAqC;CACtF,aAAa,QAAQ,OAAO;AAC9B;AAEA,SAAS,WACP,QACA,cACA,QACA,SACG;CACH,OAAO,oBAAuB,YAAY,OAAO,GAAG,QAAQ,cAAc,MAAM;AAClF;AAEA,SAAgB,gBACd,QACA,SACoB;CACpB,OAAO,WAA+B,QAAQ,iBAAiB,iBAAiB,CAAC,GAAG,OAAO;AAC7F;AAEA,SAAgB,aACd,QACA,SACiB;CACjB,OAAO,WAA4B,QAAQ,iBAAiB,cAAc,CAAC,GAAG,OAAO;AACvF;AAEA,SAAgB,qBACd,QACA,SACoB;CACpB,OAAO,WAA+B,QAAQ,iBAAiB,sBAAsB,CAAC,GAAG,OAAO;AAClG;AAEA,SAAgB,2BACd,QACA,SACiC;CACjC,OAAO,WACL,QACA,iBAAiB,4BACjB,CAAC,GACD,OACF;AACF;AAEA,SAAgB,oBACd,QACA,SACwB;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