src/withNuimo.js
function setupEmitter(error) {
      if (error) { return reject(error); }

      const sensorService = getService(SERVICE_SENSOR_UUID, peripheral);
      const notifiable = sensorService.characteristics;
      const withNotified = Promise.all(notifiable.map(characteristic =>
        new Promise((resolve, reject) =>
          void characteristic.notify([], error =>
            void (!!error ? reject(error) : resolve(characteristic))))));

      withNotified.then(characteristics => {
        const emitter = new EventEmitter();
        const onData = uuid => buffer =>
          void emitter.emit("data", { characteristic: uuid, buffer });

        characteristics.forEach(characteristic =>
          void characteristic.on('data', onData(characteristic.uuid)));

        const matrixCharacteristic =
          getCharacteristic(CHARACTERISTIC_MATRIX_UUID,
            getService(SERVICE_MATRIX_UUID, peripheral));

        resolve(new client.NuimoClient(emitter, matrixCharacteristic, peripheral));
      }).catch(reject);
    }
function setupEmitter(error) {
      if (error) { return reject(error); }

      const sensorService = getService(SERVICE_SENSOR_UUID, peripheral);
      const notifiable = sensorService.characteristics;
      const withNotified = Promise.all(notifiable.map(characteristic =>
        new Promise((resolve, reject) =>
          void characteristic.notify([], error =>
            void (!!error ? reject(error) : resolve(characteristic))))));

      withNotified.then(characteristics => {
        const emitter = new EventEmitter();
        const onData = uuid => buffer =>
          void emitter.emit("data", { characteristic: uuid, buffer });

        characteristics.forEach(characteristic =>
          void characteristic.on('data', onData(characteristic.uuid)));

        const matrixCharacteristic =
          getCharacteristic(CHARACTERISTIC_MATRIX_UUID,
            getService(SERVICE_MATRIX_UUID, peripheral));

        resolve(new client.NuimoClient(emitter, matrixCharacteristic, peripheral));
      }).catch(reject);
    }
function setupEmitter ( error ) { if ( error ) { return reject ( error ) ; } const sensorService = getService ( SERVICE_SENSOR_UUID , peripheral ) ; const notifiable = sensorService . characteristics ; const withNotified = Promise . all ( notifiable . map ( characteristic => new Promise ( ( resolve , reject ) => void characteristic . notify ( [ ] , error => void ( ! ! error ? reject ( error ) : resolve ( characteristic ) ) ) ) ) ) ; withNotified . then ( characteristics => { const emitter = new EventEmitter ( ) ; const onData = uuid => buffer => void emitter . emit ( "data" , { characteristic : uuid , buffer } ) ; characteristics . forEach ( characteristic => void characteristic . on ( 'data' , onData ( characteristic . uuid ) ) ) ; const matrixCharacteristic = getCharacteristic ( CHARACTERISTIC_MATRIX_UUID , getService ( SERVICE_MATRIX_UUID , peripheral ) ) ; resolve ( new client . NuimoClient ( emitter , matrixCharacteristic , peripheral ) ) ; } ) . catch ( reject ) ; }
setup each service characteristic of the sensor to emit data on new data
when all have been setup with characteristic.notify then resolve the promise
@param {error}
setup each service characteristic of the sensor to emit data on new data when all have been setup with characteristic . notify then resolve the promise