import { BleManager, Device } from 'react-native-ble-plx'; import { BatteryFeature, BloodPressureFeature, HeartRateFeature, TemperatureFeature, } from '../../mock'; import BaseModel from '../../../model/BaseModel'; export class Smartband { private temperatureFeature = new TemperatureFeature(); private heartRateFeature = new HeartRateFeature(); private batteryFeature = new BatteryFeature(); private bloodPressureFeature = new BloodPressureFeature(); private bleManager!: BleManager; constructor(public macAddress: string, public isMock?: boolean) { this.macAddress = macAddress; // Verifica se é classe Mock para eventuais testes isMock ?? this.makeManager(); } private makeManager(): void { this.bleManager = new BleManager(); } async connect(): Promise { return this.bleManager.connectToDevice(this.macAddress); } async disconnect(macAddress: string): Promise { return await this.bleManager.cancelDeviceConnection(macAddress); } scan(): Device[] { // eslint-disable-next-line no-array-constructor const devices = new Array(); this.bleManager.startDeviceScan(null, null, (error, device) => { if (device?.name?.includes('ST')) { devices.push(device); this.bleManager.stopDeviceScan(); } if (error) { throw new Error(error.message); } }); return devices; } getTemperature(): BaseModel { return this.temperatureFeature.execute(); } getHeartRate(): BaseModel { return this.heartRateFeature.execute(); } getBatteryLevel(): BaseModel { return this.batteryFeature.execute(); } getBloodPressure(): BaseModel { return this.bloodPressureFeature.execute(); } }