diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f0c2f77..10d44f4c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- After Service selection in node configuration Category will be automatically set to default for Service
- Interface Name for Camera Service configuration
- Support for new TV Remote services
+- Now first output is for onChange, second for onSet and third for camera snapshot. [#200](https://github.com/NRCHKB/node-red-contrib-homekit-bridged/issues/200)
### Changed
diff --git a/homekit.html b/homekit.html
index 1d5326e4..5bf67a1e 100644
--- a/homekit.html
+++ b/homekit.html
@@ -512,10 +512,14 @@
Bridge
outputs: 2,
outputLabels: function(index) {
if (index === 0) {
- return 'default'
+ return 'onChange'
}
if (index === 1) {
+ return 'onSet'
+ }
+
+ if (index === 2) {
return 'camera snapshot'
}
@@ -578,8 +582,10 @@ Bridge
.change(function() {
if (this.value === 'CameraControl') {
cameraConfiguration.fadeIn('fast')
+ node.outputs = 3
} else {
cameraConfiguration.fadeOut('fast')
+ node.outputs = 2
}
})
.change()
diff --git a/lib/cameraSource/index.js b/lib/cameraSource/index.js
index 2431dc97..4ff5548d 100644
--- a/lib/cameraSource/index.js
+++ b/lib/cameraSource/index.js
@@ -233,7 +233,7 @@ Camera.prototype.handleSnapshotRequest = function(request, callback) {
'Sending camera snapshot buffer to output...' +
JSON.stringify(msg)
)
- this.cameraNode.send([null, msg])
+ this.cameraNode.send([null, null, msg])
}
callback(undefined, imageBuffer)
diff --git a/lib/utils/ServiceUtils.js b/lib/utils/ServiceUtils.js
index 7408b7b2..ab5faa37 100644
--- a/lib/utils/ServiceUtils.js
+++ b/lib/utils/ServiceUtils.js
@@ -15,12 +15,7 @@ module.exports = function(node) {
}
}
- // eslint-disable-next-line no-unused-vars
- const onCharacteristicSet = function(newValue, callback, context) {
- callback(node.accessory.reachable === true ? null : 'no response')
- }
-
- const onCharacteristicChange = function({ oldValue, newValue, context }) {
+ const onValueChange = function(outputNumber, {oldValue, newValue, context}) {
const topic = node.topic ? node.topic : node.topic_in
const msg = { payload: {}, hap: {}, name: node.name, topic: topic }
const key = this.displayName.replace(/ /g, '').replace(/\./g, '_')
@@ -48,10 +43,33 @@ module.exports = function(node) {
debug(node.name + ' received ' + key + ': ' + newValue)
if (context || node.bridgeNode.allowMessagePassthrough) {
- node.send(msg)
+ if (outputNumber === 0) {
+ node.send(msg)
+ } else if (outputNumber === 1) {
+ node.send([null, msg])
+ }
}
}
+ // eslint-disable-next-line no-unused-vars
+ const onCharacteristicSet = function(newValue, callback, context) {
+ callback(node.accessory.reachable === true ? null : 'no response')
+
+ onValueChange.call(this, 1, {
+ undefined,
+ newValue,
+ context
+ })
+ }
+
+ const onCharacteristicChange = function({ oldValue, newValue, context }) {
+ onValueChange.call(this, 0, {
+ oldValue,
+ newValue,
+ context
+ })
+ }
+
const onInput = function(msg) {
if (msg.hasOwnProperty('payload')) {
// payload must be an object
@@ -106,13 +124,13 @@ module.exports = function(node) {
node.accessory.updateReachability(true)
if (context !== null) {
- characteristic.updateValue(
+ characteristic.setValue(
msg.payload[key],
undefined,
context
)
} else {
- characteristic.updateValue(msg.payload[key])
+ characteristic.setValue(msg.payload[key])
}
}
})
diff --git a/package.json b/package.json
index 658796d2..01d8dbff 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-homekit-bridged",
- "version": "1.0.0-dev.6",
+ "version": "1.0.0-dev.7",
"description": "Node-RED nodes to simulate Apple HomeKit devices.",
"main": "homekit.js",
"scripts": {
@@ -39,7 +39,7 @@
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
- "husky": "^4.2.0",
+ "husky": "^4.2.1",
"mocha": "^7.0.0",
"node-red": "^1.0.3",
"node-red-node-test-helper": "^0.2.3",
@@ -96,11 +96,14 @@
},
"husky": {
"hooks": {
- "pre-commit": "lint-staged && yarn lint",
- "pre-push": "yarn lint"
+ "pre-commit": "lint-staged && yarn lint",
+ "pre-push": "yarn lint"
},
"lint-staged": {
- "*.js": ["eslint --fix", "git add"]
+ "*.js": [
+ "eslint --fix",
+ "git add"
+ ]
}
}
}
diff --git a/yarn.lock b/yarn.lock
index 3fb5e8c8..c1133408 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1778,10 +1778,10 @@ https-proxy-agent@2.2.4:
agent-base "^4.3.0"
debug "^3.1.0"
-husky@^4.2.0:
- version "4.2.0"
- resolved "https://registry.yarnpkg.com/husky/-/husky-4.2.0.tgz#257dc349b1b2c7608351b6fe4cded003c5235819"
- integrity sha512-UcEAvGAZVDyzYSxiguMBEbfxqYkVk/HD2UPTKlgDbVW3QB9/Dm3TNDrGwswkrcDfBTRzRIldiTZAyMU6DP9/PA==
+husky@^4.2.1:
+ version "4.2.1"
+ resolved "https://registry.yarnpkg.com/husky/-/husky-4.2.1.tgz#b09f1bd9129e6c323cc515dc17081d0615e2d7c1"
+ integrity sha512-Qa0lRreeIf4Tl92sSs42ER6qc3hzoyQPPorzOrFWfPEVbdi6LuvJEqWKPk905fOWIR76iBpp7ECZNIwk+a8xuQ==
dependencies:
chalk "^3.0.0"
ci-info "^2.0.0"