-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZwaveJS UI : Binary Switch support (#2002)
Co-authored-by: Stéphane Escandell <stephane.escandell@sociabble.com>
- Loading branch information
1 parent
ad48004
commit fa39291
Showing
23 changed files
with
747 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
server/services/zwavejs-ui/lib/zwaveJSUI.onNodeValueUpdated.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const get = require('get-value'); | ||
const { EVENTS } = require('../../../utils/constants'); | ||
const { STATES } = require('./constants'); | ||
const { cleanNames, getDeviceFeatureId } = require('../utils/convertToGladysDevice'); | ||
|
||
/** | ||
* @description This will be called when new Z-Wave node value is updated. | ||
* @param {object} message - Data sent by ZWave JS UI. | ||
* @example zwaveJSUI.onNodeValueUpdated({data: [{node}, {value}]}); | ||
*/ | ||
async function onNodeValueUpdated(message) { | ||
// A value has been updated: https://zwave-js.github.io/node-zwave-js/#/api/node?id=quotvalue-addedquot-quotvalue-updatedquot-quotvalue-removedquot | ||
const messageNode = message.data[0]; | ||
const updatedValue = message.data[1]; | ||
const { commandClassName, propertyName, propertyKeyName, endpoint, newValue } = updatedValue; | ||
const comClassNameClean = cleanNames(commandClassName); | ||
const propertyNameClean = cleanNames(propertyName); | ||
const propertyKeyNameClean = cleanNames(propertyKeyName); | ||
let statePath = `${comClassNameClean}.${propertyNameClean}`; | ||
if (propertyKeyNameClean !== '') { | ||
statePath += `.${propertyKeyNameClean}`; | ||
} | ||
const valueConverted = get(STATES, `${statePath}.${newValue}`); | ||
|
||
const nodeId = `zwavejs-ui:${messageNode.id}`; | ||
const node = this.devices.find((n) => n.external_id === nodeId); | ||
if (!node) { | ||
return; | ||
} | ||
|
||
const featureId = getDeviceFeatureId(messageNode.id, commandClassName, endpoint, propertyName, propertyKeyName); | ||
const nodeFeature = node.features.find((f) => f.external_id === featureId); | ||
if (!nodeFeature) { | ||
return; | ||
} | ||
|
||
if (valueConverted !== undefined) { | ||
await this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, { | ||
device_feature_external_id: nodeFeature.external_id, | ||
state: valueConverted, | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
onNodeValueUpdated, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.