(topicRoot: string, payload: KeyValue, options: Partial<MqttPublishOptions>)
| 460 | } |
| 461 | |
| 462 | async iteratePayloadAttributeOutput(topicRoot: string, payload: KeyValue, options: Partial<MqttPublishOptions>): Promise<void> { |
| 463 | for (const [key, value] of Object.entries(payload)) { |
| 464 | let subPayload = value; |
| 465 | let message = null; |
| 466 | |
| 467 | // Special cases |
| 468 | if (key === "color" && utils.objectHasProperties(subPayload, ["r", "g", "b"])) { |
| 469 | subPayload = [subPayload.r, subPayload.g, subPayload.b]; |
| 470 | } |
| 471 | |
| 472 | // Check Array first, since it is also an Object |
| 473 | if (subPayload === null || subPayload === undefined) { |
| 474 | message = ""; |
| 475 | } else if (Array.isArray(subPayload)) { |
| 476 | message = subPayload.map((x) => `${x}`).join(","); |
| 477 | } else if (typeof subPayload === "object") { |
| 478 | await this.iteratePayloadAttributeOutput(`${topicRoot}${key}-`, subPayload, options); |
| 479 | } else { |
| 480 | message = typeof subPayload === "string" ? subPayload : stringify(subPayload); |
| 481 | } |
| 482 | |
| 483 | if (message !== null) { |
| 484 | await this.mqtt.publish(`${topicRoot}${key}`, message, options); |
| 485 | } |
| 486 | } |
| 487 | } |
| 488 | } |
no test coverage detected