///
import EventEmitter from 'event-emitter-for-miniprogram';
import { BlueToothAdapter4Mp, DeviceFilterFunction } from 'qcloud-iotexplorer-bluetooth-adapter';
import { BluetoothAutomationRuntimeMode } from './constants';
import { BluetoothAutomationModel } from './models';
import { BluetoothAutomationReporter, BluetoothAutomationReportHandler } from './BluetoothAutomationReporter';
import { BluetoothAutomationUserConfig } from './BluetoothAutomationUserConfig';
import { BluetoothMonitor } from './BluetoothMonitor';
import { BluetoothDeviceMonitor } from './BluetoothDeviceMonitor';
import { SimpleStore } from './utils';
import { WechatDeviceTicketManager } from './WechatDeviceTicketManager';
interface SetBluetoothBackgroundModeContext {
targetEnable: boolean;
completed: boolean;
cancelled: boolean;
promiseObj: {
promise: Promise;
resolve: () => void;
reject: (reason?: unknown) => void;
};
}
interface DeviceSelector {
explorerDeviceId?: string;
bluetoothDeviceId?: string;
}
interface BluetoothAutomationConfig {
explorerDeviceId: string;
bluetoothDeviceId: string;
mode: string;
sn: string;
modelId: string;
}
export interface DeviceAutomationEventParams {
explorerDeviceId: string;
bluetoothDeviceId: string;
}
declare const BaseClass: new (...args: any[]) => EventEmitter & import("./configMixin").ConfigStore;
export declare class BluetoothAutomationManager extends BaseClass {
readonly blueToothAdapter: BlueToothAdapter4Mp;
readonly reporter: BluetoothAutomationReporter;
protected deviceFilters: Array;
protected inited: boolean;
protected busyDeviceIdMap: Record;
protected inUseDeviceIdMap: Record;
protected updateTimer: unknown | null;
protected lastUpdateTime: number;
protected deviceMonitorStore: SimpleStore;
protected bluetoothAdapterLastAvailable: boolean | undefined;
protected wechatDeviceTicketMgr: WechatDeviceTicketManager;
protected isIOS: boolean;
protected bluetoothMonitor: BluetoothMonitor;
protected model: BluetoothAutomationModel;
protected runtimeMode: BluetoothAutomationRuntimeMode;
protected entryPackage: string | undefined;
protected cleanupHandlerList: Array<() => void>;
protected deviceMonitoredEventHandlingFlag: Record;
protected isDevModeExternal: () => boolean;
protected setBluetoothBackgroundModeContext: Record;
constructor({ blueToothAdapter, requestApi, entryPackage, reporter, isDevMode, getDeviceTicket, }: {
blueToothAdapter: BlueToothAdapter4Mp;
requestApi: (action: string, params: T) => Promise;
getDeviceTicket: (explorerDeviceId: string) => Promise<{
sn: string;
snTicket: string;
modelId: string;
}>;
entryPackage?: string;
reporter?: BluetoothAutomationReportHandler;
isDevMode?: () => boolean;
});
init({ runtimeMode }?: {
runtimeMode?: BluetoothAutomationRuntimeMode;
}): void;
destroy({ keepConnection }?: {
keepConnection?: boolean;
}): void;
injectBluetoothAdapter(): void;
get isInited(): boolean;
get isSupported(): boolean;
notifyDeviceAdapterBusy(explorerDeviceId: string): () => void;
notifyDeviceAdapterInUse(explorerDeviceId: string): () => void;
isDeviceAdapterBusy(explorerDeviceId: string): boolean;
isDeviceAdapterInUse(explorerDeviceId: string): boolean;
getDeviceMonitor(selector: DeviceSelector): BluetoothDeviceMonitor | null;
handleAdapterStateChange({ available }: {
available: any;
}): void;
autoMonitorDevices(): Promise;
/** 不调用微信 API,直接清空全部设置 */
disableAllDeviceAutomations(): Promise;
enableDeviceAutomation({ explorerDeviceId, bluetoothDeviceId, mode, }: {
explorerDeviceId: string;
bluetoothDeviceId: string;
mode: string;
}): Promise;
disableDeviceAutomation({ explorerDeviceId, disableBackgorundModeImmediately, }: {
explorerDeviceId: string;
disableBackgorundModeImmediately?: boolean;
}): Promise;
modifyDeviceAutomationMode({ explorerDeviceId, mode }: {
explorerDeviceId: string;
mode: string;
}): Promise;
getDeviceAutomationAvailableModes(explorerDeviceId: string): Promise<{
modes: string[];
preferredMode?: string;
labels: string[];
devModeLabels: string[];
}>;
isDeviceAutomationEnabled(explorerDeviceId: string): Promise;
getDeviceAutomationMode(explorerDeviceId: string): Promise;
setBluetoothBackgroundMode(options: {
explorerDeviceId: string;
bluetoothDeviceId: string;
enable: boolean;
}): Promise;
invokeBluetoothBackgroundModeSet(options: {
explorerDeviceId: string;
bluetoothDeviceId: string;
enable: boolean;
}): Promise;
onCreateDeviceMonitor(handler: (monitorInstance: BluetoothDeviceMonitor) => void): void;
offCreateDeviceMonitor(handler?: (monitorInstance: BluetoothDeviceMonitor) => void): void;
onEnableDeviceAutomation(handler: (monitorInstance: DeviceAutomationEventParams) => void): void;
offEnableDeviceAutomation(handler?: (monitorInstance: DeviceAutomationEventParams) => void): void;
onDisableDeviceAutomation(handler: (monitorInstance: DeviceAutomationEventParams) => void): void;
offDisableDeviceAutomation(handler?: (monitorInstance: DeviceAutomationEventParams) => void): void;
isMonitoringDevice(explorerDeviceId: string): boolean;
getRuntimeMode(): BluetoothAutomationRuntimeMode;
setRuntimeMode(runtimeMode: BluetoothAutomationRuntimeMode): void;
requestUserAuth(): Promise;
get isRunning(): boolean;
getEnabledDeviceCount(): Promise;
isDevMode(): boolean;
filterAdvInfo({ productId, deviceName, advInfo, }: {
productId: string;
deviceName: string;
advInfo: WechatMiniprogram.BlueToothDevice;
}): import("qcloud-iotexplorer-bluetooth-adapter").BlueToothDeviceInfo;
/** 微信蓝牙监听接口回调 */
handleDeviceMonitored(bluetoothDeviceId: string, { triggerManually, }?: {
triggerManually?: boolean;
}): Promise;
protected clearAutomationConfig(): Promise;
protected createDeviceMonitor(config: BluetoothAutomationUserConfig): BluetoothDeviceMonitor;
protected destroyDeviceMonitor(selector: DeviceSelector): void;
protected startUpdate(): void;
protected stopUpdate(): void;
protected handleUpdate(): void;
protected addListenerWithCleanup(eventEmitter: EventEmitter, eventName: string, handler: (params: unknown) => void): void;
protected detectRuntimeMode(): BluetoothAutomationRuntimeMode;
}
export {};