NRCHKB / node-red-contrib-homekit-bridged

Node-RED Contribution - HomeKit Bridged : Node-RED nodes to simulate Apple HomeKit devices.
https://nrchkb.github.io
MIT License
412 stars 52 forks source link

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

Open lougreenwood opened 1 year ago

lougreenwood commented 1 year ago

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

deancs commented 1 year ago

+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.

Shaquu commented 1 year ago

+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 :)

petrica commented 2 weeks ago

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!

Shaquu commented 2 weeks ago

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

petrica commented 2 weeks ago

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.

Shaquu commented 2 weeks ago

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.
petrica commented 2 weeks ago

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

GogoVega commented 2 weeks ago

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.