diff --git a/README.md b/README.md index d849f86f..181f6b0d 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,21 @@ Context info can be provided as part of the input message and will be available } ``` +## No Response + +You can set accessory "No Response" status by sending "NO_RESPONSE" as a value for any available characteristic. + +**Example**: + +```json +{ + "On": "NO_RESPONSE" +} +``` + +After "No Response" status was triggered, the accessory is marked accordingly when you try to control it or reopen Home.app. +Any subsequent update of any characteristic value will reset this status. + ## FAQ #### How can I generate Debug logs? diff --git a/lib/HAPServiceNode.js b/lib/HAPServiceNode.js index 24bf3e66..cc564c47 100644 --- a/lib/HAPServiceNode.js +++ b/lib/HAPServiceNode.js @@ -101,7 +101,7 @@ module.exports = function(RED) { service.on("characteristic-change", ServiceUtils.onCharacteristicChange); // Which characteristics are supported? - this.supported = CharacteristicUtils.getSupported(service); + this.supported = CharacteristicUtils.getSupportedAndSubscribeSet(service); // Respond to inputs this.on("input", ServiceUtils.onInput); diff --git a/lib/utils/CharacteristicUtils.js b/lib/utils/CharacteristicUtils.js index 98d3955c..704884f7 100644 --- a/lib/utils/CharacteristicUtils.js +++ b/lib/utils/CharacteristicUtils.js @@ -27,7 +27,7 @@ module.exports = function(node) { return characteristicProperties; }; - const getSupported = function (service) { + const getSupportedAndSubscribeSet = function (service) { const supported = {read: [], write: []}; const allCharacteristics = service.characteristics.concat( @@ -40,6 +40,15 @@ module.exports = function(node) { .replace(/\./g, "_"); if (characteristic.props.perms.indexOf("pw") > -1) { supported.read.push(cKey); + + // Subscribe to 'get' event of readable characteristic + characteristic.on("get", function(callback, context) { + if (node.accessory.reachable === true) { + callback(null, characteristic.value); + } else { + callback("no response", null); + } + }); } if ( @@ -48,6 +57,11 @@ module.exports = function(node) { -2 ) { supported.write.push(cKey); + + // Subscribe to 'set' event of writable characteristic + characteristic.on("set", function(newVal, callback) { + callback(node.accessory.reachable === true ? null : "no response"); + }); } //Allow for negative temperatures @@ -61,6 +75,6 @@ module.exports = function(node) { return { load: load, - getSupported: getSupported + getSupportedAndSubscribeSet: getSupportedAndSubscribeSet }; }; diff --git a/lib/utils/ServiceUtils.js b/lib/utils/ServiceUtils.js index cf9362ca..96ca6d5a 100644 --- a/lib/utils/ServiceUtils.js +++ b/lib/utils/ServiceUtils.js @@ -67,11 +67,14 @@ module.exports = function(node) { const noResponseMsg = "NO_RESPONSE"; if (msg.payload[key] === noResponseMsg) { + node.accessory.updateReachability(false); characteristic.setValue(new Error(noResponseMsg)); return; } + node.accessory.updateReachability(true); + if (context !== null) { characteristic.setValue(msg.payload[key], undefined, context); } else {