Skip to content

Commit

Permalink
feat(wait-until): Add ability to use mustache templates for entity id…
Browse files Browse the repository at this point in the history
… field

- Add entity_id as a input property

Closes #189
  • Loading branch information
zachowj committed Jan 14, 2020
1 parent 8f25ef6 commit 6d9e183
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
22 changes: 12 additions & 10 deletions docs/node/wait-until.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ When an input is received the node will wait until the condition is met or the t
### Entity ID <Badge text="required"/>

- Type: `string`
- Accepts [Mustache Templates](/guide/mustache-templates.md)

The id of an entity to use for the comparison.

Expand Down Expand Up @@ -46,16 +47,17 @@ If the received message has this property set to any value the node will be set

Override config values by passing in a property with a valid value.

- entityId
- property
- comparator
- value
- valueType
- timeout
- timeoutUnits
- entityLocation
- entityLocationType
- checkCurrentState
- `entity_id`
- `entityId` <Badge type="warning" text="deprecated" />
- `property`
- `comparator`
- `value`
- `valueType`
- `timeout`
- `timeoutUnits`
- `entityLocation`
- `entityLocationType`
- `checkCurrentState`

## Output

Expand Down
21 changes: 16 additions & 5 deletions nodes/wait-until/wait-until.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = function(RED) {
const Joi = require('@hapi/joi');
const EventsNode = require('../../lib/events-node');
const EventsNode = require('../../lib/events-node');
const Joi = require('@hapi/joi');
const RenderTemplate = require('../../lib/mustache-context');

module.exports = function(RED) {
const nodeOptions = {
config: {
name: {},
Expand All @@ -26,7 +27,7 @@ module.exports = function(RED) {
},
input: {
entityId: {
messageProp: 'payload.entityId',
messageProp: ['payload.entity_id', 'payload.entityId'],
configProp: 'entityId',
validation: {
haltOnFail: true,
Expand Down Expand Up @@ -201,8 +202,18 @@ module.exports = function(RED) {
return null;
}

const entityId =
parsedMessage.entityId.source === 'message'
? parsedMessage.entityId.value
: RenderTemplate(
parsedMessage.entityId.value,
message,
node.node.context(),
node.utils.toCamelCase(node.nodeConfig.server.name)
);

node.savedConfig = {
entityId: parsedMessage.entityId.value,
entityId: entityId,
property: parsedMessage.property.value,
comparator: parsedMessage.comparator.value,
value: parsedMessage.value.value,
Expand Down

0 comments on commit 6d9e183

Please sign in to comment.