mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-16 14:18:54 +01:00
Fix crash when trying to get/set power state
- Call getPowerState on the object instead of passing the function to fix undefined isActivity error - Remove callback param from setPowerState since it is not called with a callback param. - startActivity expects the activity id as a parameter. We can't actually toggle activities off and on. There is a "PowerOff" activity that will turn everything off.
This commit is contained in:
@@ -163,9 +163,9 @@ LogitechHarmonyAccessory.prototype = {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (this.isActivity) {
|
if (this.isActivity) {
|
||||||
hub.getCurrentActivity().then(function (currentActivity) {
|
this.hub.getCurrentActivity().then(function (currentActivity) {
|
||||||
callback(currentActivity.id === self.id);
|
callback(currentActivity === self.id);
|
||||||
}).except(function (err) {
|
}).catch(function (err) {
|
||||||
self.log('Unable to get current activity with error', err);
|
self.log('Unable to get current activity with error', err);
|
||||||
callback(false);
|
callback(false);
|
||||||
});
|
});
|
||||||
@@ -175,28 +175,23 @@ LogitechHarmonyAccessory.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setPowerState: function (state, callback) {
|
setPowerState: function (state) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (this.isActivity) {
|
if (this.isActivity) {
|
||||||
this.log('Set activity ' + this.name + ' power state to ' + state);
|
this.log('Set activity ' + this.name + ' power state to ' + state);
|
||||||
|
|
||||||
// Activity id -1 is turn off all devices
|
this.hub.startActivity(self.id)
|
||||||
var id = state ? this.id : -1;
|
|
||||||
|
|
||||||
this.hub.startActivity(id)
|
|
||||||
.then(function () {
|
.then(function () {
|
||||||
self.log('Finished setting activity ' + self.name + ' power state to ' + state);
|
self.log('Finished setting activity ' + self.name + ' power state to ' + state);
|
||||||
callback();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
self.log('Failed setting activity ' + self.name + ' power state to ' + state + ' with error ' + err);
|
self.log('Failed setting activity ' + self.name + ' power state to ' + state + ' with error ' + err);
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO: Support setting device power
|
// TODO: Support setting device power
|
||||||
this.log('TODO: Support setting device power');
|
this.log('TODO: Support setting device power');
|
||||||
callback();
|
// callback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -284,7 +279,9 @@ LogitechHarmonyAccessory.prototype = {
|
|||||||
onUpdate: function (value) {
|
onUpdate: function (value) {
|
||||||
self.setPowerState(value)
|
self.setPowerState(value)
|
||||||
},
|
},
|
||||||
onRead: self.getPowerState,
|
onRead: function(callback) {
|
||||||
|
self.getPowerState(callback)
|
||||||
|
},
|
||||||
perms: ["pw","pr","ev"],
|
perms: ["pw","pr","ev"],
|
||||||
format: "bool",
|
format: "bool",
|
||||||
initialValue: 0,
|
initialValue: 0,
|
||||||
@@ -300,6 +297,5 @@ LogitechHarmonyAccessory.prototype = {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.accessory = LogitechHarmonyAccessory;
|
|
||||||
module.exports.platform = LogitechHarmonyPlatform;
|
module.exports.platform = LogitechHarmonyPlatform;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user