node-red-contrib-homekit-bridged icon indicating copy to clipboard operation
node-red-contrib-homekit-bridged copied to clipboard

[Feature]: Pass through `meta` from `msg`

Open lougreenwood opened this issue 1 year ago • 8 comments

Your Current NRCHKB Plugin Version

1.5.0

Operating System

No response

What is your idea?

When a NK service node is triggered, it should be possible to pass additional metadata through the service node and receive that metadata on the output.

For example, if I pass the following data to a switch, I would expect the following output:

Service node input

msg: {
  payload: {
    On: true
  },
  meta: {
    someMetaValue: 123,
  }
}

Service node output

msg: {
  payload: {
    On: true
  },
  hap: { ... },
  name: 'device name',
  meta: {
    someMetaValue: 123,
  }
}

I already have message passthrough enabled, but it seems that a service node builds a completely new message and disregards almost all values passed to it's input.

Any more details?

If this is specific to some hardware or specific software version, please explain here.

Additional comments?

Additional comments here, if any.

Any code or functions to add?

No response

lougreenwood avatar Dec 27 '22 08:12 lougreenwood

+1 for this request. Thanks for a great addition to NR. Its pretty much a NR convention that msg objects are passed-through with the node only making the specified changes based on its function.

deancs avatar Jun 24 '23 23:06 deancs

+1 for this request. Thanks for a great addition to NR. Its pretty much a NR convention that msg objects are passed-through with the node only making the specified changes based on its function.

Noted :)

Shaquu avatar Jul 02 '23 19:07 Shaquu

Hi! This should be marked as must have, not enhancement, as it is nearly impossible to stop any loop without the pass-through. The plugin is highly customizable and works very well, apart from this trivial to fix issue. Thank you!

petrica avatar Jun 17 '24 21:06 petrica

Hello, will look into this. @crxporter any thoughts?

Shaquu avatar Jun 17 '24 22:06 Shaquu

Apologies, just read the section: https://nrchkb.github.io/wiki/nodes/output-messages/#differentiate-between-passthrough-or-from-homekit-messages on how to stop loops.

petrica avatar Jun 17 '24 22:06 petrica

This one is tough to implement. @lougreenwood

  1. we have original message on input
  2. then we trigger HomeKit characteristic set value which is async
  3. it triggers callback which sends msg to output, but it has no context of 1.

Shaquu avatar Jun 18 '24 21:06 Shaquu

I see that this is deprecated, however at the moment you can use the Context attribute to pass an object from the input to the output:

Input:

msg: {
  payload: {
    Context: 'Some value here'
  }
}

https://github.com/NRCHKB/node-red-contrib-homekit-bridged/blob/6f71cac9030556506082ac53b6d0b4fafbd702c9/src/lib/utils/ServiceUtils.ts#L250-L254

Output:

msg: {
  hap: {
    context: 'Some value here'   
  }
}

https://github.com/NRCHKB/node-red-contrib-homekit-bridged/blob/6f71cac9030556506082ac53b6d0b4fafbd702c9/src/lib/utils/ServiceUtils.ts#L45-L47

petrica avatar Jun 19 '24 08:06 petrica

In fact, onInput should be asynchronous - it should wait for the response from the callback then send the message (original msg + hap response). Currently this function only takes msg as argument which makes it synchronous, it should take 3.

GogoVega avatar Jun 19 '24 09:06 GogoVega