// Mock BLE Manager для iOS Simulator (Bluetooth недоступен) import { IBLEManager, WPDevice, WiFiNetwork, WiFiStatus } from './types'; const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); export class MockBLEManager implements IBLEManager { private connectedDevices = new Set(); private mockDevices: WPDevice[] = [ { id: 'mock-743', name: 'WP_497_81a14c', mac: '142B2F81A14C', rssi: -55, wellId: 497, }, { id: 'mock-769', name: 'WP_523_81aad4', mac: '142B2F81AAD4', rssi: -67, wellId: 523, }, ]; async scanDevices(): Promise { console.log('[MockBLE] Scanning for devices...'); await delay(2000); // Simulate scan delay return this.mockDevices; } stopScan(): void { console.log('[MockBLE] Scan stopped'); } async connectDevice(deviceId: string): Promise { console.log(`[MockBLE] Connecting to ${deviceId}...`); await delay(1000); this.connectedDevices.add(deviceId); return true; } async disconnectDevice(deviceId: string): Promise { console.log(`[MockBLE] Disconnecting ${deviceId}`); await delay(500); this.connectedDevices.delete(deviceId); } isDeviceConnected(deviceId: string): boolean { return this.connectedDevices.has(deviceId); } async sendCommand(deviceId: string, command: string): Promise { console.log(`[MockBLE] Sending command: ${command}`); await delay(500); // Simulate responses if (command === 'pin|7856') { return 'pin|ok'; } if (command === 'w') { return 'mac,142b2f81a14c|w|3|FrontierTower,-55|HomeNetwork,-67|TP-Link_5G,-75'; } if (command === 'a') { return 'mac,142b2f81a14c|a|FrontierTower,-67'; } if (command.startsWith('W|')) { return 'mac,142b2f81a14c|W|ok'; } return 'ok'; } async getWiFiList(deviceId: string): Promise { console.log(`[MockBLE] Getting WiFi list for ${deviceId}`); await delay(1500); return [ { ssid: 'FrontierTower', rssi: -55 }, { ssid: 'HomeNetwork', rssi: -67 }, { ssid: 'TP-Link_5G', rssi: -75 }, { ssid: 'Office-WiFi', rssi: -80 }, ]; } async setWiFi( deviceId: string, ssid: string, password: string ): Promise { console.log(`[MockBLE] Setting WiFi: ${ssid}`); await delay(2000); return true; } async getCurrentWiFi(deviceId: string): Promise { console.log(`[MockBLE] Getting current WiFi for ${deviceId}`); await delay(1000); return { ssid: 'FrontierTower', rssi: -67, connected: true, }; } async rebootDevice(deviceId: string): Promise { console.log(`[MockBLE] Rebooting ${deviceId}`); await delay(500); this.connectedDevices.delete(deviceId); } /** * Cleanup all BLE connections and state * Should be called on app logout to properly release resources */ async cleanup(): Promise { console.log('[MockBLE] Cleanup: disconnecting all devices'); // Disconnect all connected devices const deviceIds = Array.from(this.connectedDevices); for (const deviceId of deviceIds) { await this.disconnectDevice(deviceId); } this.connectedDevices.clear(); console.log('[MockBLE] Cleanup: complete'); } }