import Ember from 'ember';

export default Ember.Service.extend({
  device: null,
  server: null,
  service: null,
  characteristic: null,

  isAvailable() {
    return 'bluetooth' in navigator;
  },

  async connectDevice(options) {
    let device = await navigator.bluetooth.requestDevice(options);
    let server = await device.gatt.connect();

    console.log(`Connected to bluetooth device: ${device.name}`);

    this.set('device', device);
    this.set('server', server);
  },

  async readValue(serviceName, characteristicName) {
    let service = await this.get('server').getPrimaryService(serviceName);
    let characteristic = await service.getCharacteristic(characteristicName);
    let value = await characteristic.readValue();

    return value.getUint8(0);
  }
});

@@ -471,16 +471,70 @@
 server);
+%0A%0A    return  Ember.RSVP.Promise.resolve(device.name);
 %0A  %7D,%0A%0A 
@@ -800,16 +800,43 @@
  return 
+Ember.RSVP.Promise.resolve(
 value.ge
@@ -844,16 +844,17 @@
 Uint8(0)
+)
 ;%0A  %7D%0A%7D)

Return promise in service methods