Skip to content

Commit

Permalink
Add togglePower() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafostar committed Sep 17, 2019
1 parent 91c21de commit 15a4b2d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ module.exports = class Client
{
var func = {
turnOn: this.changePower.bind(this, deviceId, 'on'),
turnOff: this.changePower.bind(this, deviceId, 'standby')
turnOff: this.changePower.bind(this, deviceId, 'standby'),
togglePower: this.togglePower.bind(this, deviceId)
};

if(this.devices[deviceId].name === 'TV')
Expand Down Expand Up @@ -472,6 +473,23 @@ module.exports = class Client
});
}

togglePower(deviceId)
{
return new Promise((resolve, reject) =>
{
this.getStatus(deviceId).then(value =>
{
var action = (value === 'on') ? 'standby'
: (value === 'standby') ? 'on' : null;

if(action)
this.changePower(deviceId, action).then(resolve);
else
resolve(null);
});
});
}

changeActive(isActiveSource)
{
return new Promise((resolve, reject) =>
Expand Down

0 comments on commit 15a4b2d

Please sign in to comment.