UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 1.4 kB
"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var o in e)d(n,o,{get:e[o],enumerable:!0})},v=(n,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of y(e))!m.call(n,t)&&t!==o&&d(n,t,{get:()=>e[t],enumerable:!(r=l(e,t))||r.enumerable});return n};var h=n=>v(d({},"__esModule",{value:!0}),n);var C={};S(C,{default:()=>c});module.exports=h(C);var a=require("../../helpers/node"),p=require("../events/Events");class c{constructor({homeAssistant:e,jsonataService:o,nodeRedContextService:r,node:t,status:s,typedInputService:i}){this.homeAssistant=e,this.contextService=r,this.jsonataService=o,this.node=t,this.status=s,this.typedInputService=i,t.on(p.NodeEvent.Close,this.#e.bind(this));const u=this.node?.config?.name??"undefined";t.debug(`instantiated node, name: ${u}`)}debugToClient(e){(0,a.debugToClient)(this.node,e)}async setCustomOutputs(e=[],o,r){for(const t of e){const s=await this.typedInputService.getValue(t.value,t.valueType,{message:o,...r});try{this.contextService.set(s,t.propertyType,t.property,o)}catch(i){this.node.warn(`Custom Ouput Error (${t.propertyType}:${t.property}): ${i}`)}}}#e(e,o){this.node.debug(`closing node. Reason: ${e?"node deleted":"node re-deployed"}`);try{this.onClose?.(e),o()}catch(r){r instanceof Error?o(r):o(new Error(r))}}}