export class FakeBluetoothDevice { gatt : BluetoothRemoteGATTServer ; private listeners : { [ key in 'gattserverdisconnected' ] : EventListener [ ] ; } = { gattserverdisconnected : [ ] } ; constructor ( public id , public name ) { } addEventListener ( type , listener ) { this . listeners [ type ] = [ ... this . listeners [ type ] , listener ] ; } disconnect ( ) { const mockedEvent = { target : this } as unknown ; this . listeners . gattserverdisconnected . forEach ( listener => listener ( mockedEvent as Event ) ) ; } clear ( ) { this . id = undefined ; this . name = undefined ; this . listeners = { gattserverdisconnected : [ ] } ; } } export class FakeBluetoothRemoteGATTServer { connected = false ; constructor ( public device , public services ) { device . gatt = this ; } connect ( ) { this . connected = true ; return Promise . resolve ( this ) ; } getPrimaryService ( service ) { return Promise . resolve ( this . services [ service ] . service ) ; } disconnect ( ) { this . device . disconnect ( ) ; this . connected = false ; } } export class FakeBluetoothRemoteGATTService { constructor ( public device , public characteristics ) { this . characteristics . service = this ; } getCharacteristic ( characteristic ) { return Promise . resolve ( this . characteristics [ characteristic ] ) ; } } export class FakeBluetoothRemoteGATTCharacteristic { value : DataView ; properties : BluetoothCharacteristicProperties ; private readonly initialValue : DataView ; private listeners : { [ key in 'characteristicvaluechanged' ] : EventListener [ ] ; } = { characteristicvaluechanged : [ ] } ; constructor ( properties , initialValue ? ) { this . properties = properties ; this . value = initialValue ; this . initialValue = initialValue ; } readValue ( ) { return Promise . resolve ( this . value ) ; } addEventListener ( type , listener ) { this . listeners [ type ] = [ ... this . listeners [ type ] , listener ] ; } changeValue ( value ) { this . value = value ; const mockedEvent = { target : this } as unknown ; this . listeners . characteristicvaluechanged . forEach ( listener => listener ( mockedEvent as Event ) ) ; } clear ( ) { this . value = this . initialValue ; this . listeners = { characteristicvaluechanged : [ ] } ; } }