From 03293409dd8e08f6a70d5535f93a51149640eaf6 Mon Sep 17 00:00:00 2001 From: Chloe Stars Date: Fri, 10 Jul 2015 15:50:07 -0700 Subject: [PATCH] Add support for getting the state of the power to WeMo accessories. --- accessories/WeMo.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/accessories/WeMo.js b/accessories/WeMo.js index 6684370..0313878 100644 --- a/accessories/WeMo.js +++ b/accessories/WeMo.js @@ -54,6 +54,28 @@ WeMoAccessory.prototype = { }); }, + getPowerState: function(callback) { + + if (!this.device) { + this.log("No '"+this.wemoName+"' device found (yet?)"); + return; + } + + var that = this; + + this.log("checking power state for: " + this.wemoName); + this.device.getBinaryState(function(err, result) { + if (!err) { + var binaryState = parseInt(result) + that.log("power state for " + that.wemoName + " is: " + binaryState) + callback(binaryState) + } + else { + that.log(err) + } + }); + }, + getServices: function() { var that = this; return [{ @@ -124,6 +146,11 @@ WeMoAccessory.prototype = { },{ cType: types.POWER_STATE_CTYPE, onUpdate: function(value) { that.setPowerState(value); }, + onRead: function(callback) { + that.getPowerState(function(powerState){ + callback(powerState); + }); + }, perms: ["pw","pr","ev"], format: "bool", initialValue: false,