Skip to content

Commit

Permalink
Merge 67368eb into 7ae2c23
Browse files Browse the repository at this point in the history
  • Loading branch information
gcampax committed Aug 23, 2018
2 parents 7ae2c23 + 67368eb commit b37b0fd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 149 deletions.
71 changes: 43 additions & 28 deletions org.thingpedia.bluetooth.speaker.a2dp/device.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna <gcampagn@cs.stanford.edu>
// Copyright 2015-2018 Giovanni Campagna <gcampagn@cs.stanford.edu>
//
// See LICENSE for details
"use strict";

const Tp = require('thingpedia');

const VolumeBase = require('./volume_adjust_base');
const RaiseVolume = VolumeBase('RaiseVolume', true, +1);
const LowerVolume = VolumeBase('LowerVolume', true, -1);
const SetVolume = VolumeBase('SetVolume', false);

const BluetoothA2dpSinkDevice = new Tp.DeviceClass({
Name: 'BluetoothA2dpSinkDevice',

UseDiscovery(engine, publicData, privateData) {
module.exports = class BluetoothA2dpSinkDevice extends Tp.BaseDevice {
static loadFromDiscovery(engine, publicData, privateData) {
return new BluetoothA2dpSinkDevice(engine,
{ kind: 'org.thingpedia.bluetooth.speaker.a2dp',
discoveredBy: engine.ownTier,
Expand All @@ -23,10 +17,10 @@ const BluetoothA2dpSinkDevice = new Tp.DeviceClass({
class: publicData.class,
hwAddress: privateData.address,
alias: privateData.alias }, true);
},
}

_init(engine, state) {
this.parent(engine, state);
constructor(engine, state) {
super(engine, state);

this.alias = state.alias;
this.hwAddress = state.hwAddress;
Expand All @@ -36,7 +30,7 @@ const BluetoothA2dpSinkDevice = new Tp.DeviceClass({

this.name = "A2DP Bluetooth Speaker %s".format(this.alias);
this.description = "This is a Bluetooth speaker capabable of playing high-fidelity music";
},
}

completeDiscovery(delegate) {
if (this.state.paired) {
Expand All @@ -58,7 +52,7 @@ const BluetoothA2dpSinkDevice = new Tp.DeviceClass({
}).catch((e) => {
delegate.configFailed(e);
});
},
}

checkAvailable() {
if (!this.engine.platform.hasCapability('bluetooth'))
Expand All @@ -71,19 +65,40 @@ const BluetoothA2dpSinkDevice = new Tp.DeviceClass({
else
return Tp.Availability.UNAVAILABLE;
});
},
}

getActionClass(id) {
switch(id) {
case 'raise_volume':
return RaiseVolume;
case 'lower_volume':
return LowerVolume;
case 'set_volume':
return SetVolume;
default:
return this.parent(id);
async _doSetVolume(relative, value) {
const audioRouter = this.engine.platform.getCapability('audio-router');
const audioManager = this.engine.platform.getCapability('audio-manager');
const isBluetooth = await audioRouter.isAudioRouteBluetooth(this.hwAddress);
if (!isBluetooth) {
console.log(this.device.uniqueId + ' is not the current audio sink, ignoring volume change request');
return;
}

if (relative)
await audioManager.adjustMediaVolume(value, false);
else
await audioManager.setMediaVolume(value, false);
}

do_raise_volume() {
return this._doSetVolume(true, +1);
}
do_lower_volume() {
return this._doSetVolume(true, -1);
}
do_set_volume({ percent }) {
return this._doSetVolume(false, percent);
}
async do_play_music() {
const audioRouter = this.engine.platform.getCapability('audio-router');
const systemApps = this.engine.platform.getCapability('system-apps');
await audioRouter.setAudioRouteBluetooth(this.hwAddress);
return systemApps.startMusic();
}
async do_set_sink() {
const audioRouter = this.engine.platform.getCapability('audio-router');
return audioRouter.setAudioRouteBluetooth(this.hwAddress);
}
});
module.exports = BluetoothA2dpSinkDevice;
};
38 changes: 0 additions & 38 deletions org.thingpedia.bluetooth.speaker.a2dp/play_music.js

This file was deleted.

35 changes: 0 additions & 35 deletions org.thingpedia.bluetooth.speaker.a2dp/set_sink.js

This file was deleted.

48 changes: 0 additions & 48 deletions org.thingpedia.bluetooth.speaker.a2dp/volume_adjust_base.js

This file was deleted.

0 comments on commit b37b0fd

Please sign in to comment.